Educoder jQuery动画

目录

Educoder jQuery动画

第1关:jQuery动画效果——隐藏/显示

第2关:jQuery动画效果——淡入淡出

第3关:jQuery动画效果——滑动

第4关:jQuery动画效果——自定义动画


Educoder jQuery动画

第1关:jQuery动画效果——隐藏/显示

<!doctype html>
<html lang="en">

	<head>
		<meta charset="UTF-8">
		<title>Document</title>
		<script src="https://code.jquery.com/jquery-3.3.1.min.js"></script>

		<style>
			.container {
                width: 200px;
				margin: 30px auto;
			}
			
			.item {
				width: 170px;
				height: 170px;
				background: orange;
			}
			
			button {
				margin: 0 10px 20px 0;
			}
		</style>
	</head>

	<body>
		<div class="container">
			<button class="hide">隐藏</button>
			<button class="show">显示</button>
			<button class="toggle">toggle</button>
			<div class="item"></div>
		</div>

		<script>
			$(function() {
				//------------begin---------
                $(".hide").click(function(){
                    $(".item").hide("slow",function(){
                        alert("我隐藏了");
                    })
                });
                $(".show").click(function(){
                    $(".item").show(1000,function(){
                        alert("我显示了");
                    })
                });
				$(".toggle").click(function(){
                    $(".item").toggle("fast",function(){
                        alert("隐藏显示的切换");
                    })
                });
        
                
                //-----------end------------
			})
		</script>
	</body>

</html>

第2关:jQuery动画效果——淡入淡出

<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
    <script src="https://code.jquery.com/jquery-3.3.1.min.js"></script>

    <style>
       .container {
            width: 60%;
            height: 260px;
            margin: 30px auto;
        }                   
       button{
            margin: 100px 20px 0 0 ;
            float: left;
        }
       img{
           width: 200px;
           height: 200px;
           float: left;
           margin-right: 30px;
       }
    </style>
</head>
<body>
    <div class="container">
         <button class="btn">动画开始</button>
         <img class="first" src="https://www.educoder.net/attachments/download/206411"/>
         <img class="second" src="https://www.educoder.net/attachments/download/206410" />
    </div>
 </div>
   <script>
    $(function(){
        
        $(".btn").click(function(){       
        // ---------- Begin -----------
        $(".first").fadeTo(2000,0.5);
        $(".second").delay(2000).fadeTo(2000,0.5);
        $(".first").delay(2000).fadeOut("slow");
        $(".second").fadeOut("slow")    
            
            

        // ---------- End -----------
        })
    })
   </script>
</body>
</html>

第3关:jQuery动画效果——滑动

<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
    <script src="https://code.jquery.com/jquery-3.3.1.min.js"></script>
    <style>
     .menu{
         width: 120px;
         margin: 20px auto;
     }
     span{
         line-height: 50px;
         font-size: 20px;
         margin-left: 36px;
     }
     .list{
         width: 100px;
        line-height: 18px;
        border: 2px solid #888;
        padding: 0 10px;
        display: none;
     }

    </style>
</head>
<body>
    <div class="menu">
         <span>菜单</span>
        <div class="list">
            <p>新建课堂</p>
            <p>新建实训</p>
            <p>新建实训路径</p>
            <p>新建项目</p>
         </div>
    </div>
    <script>
     $(function(){
         
         //-------------- Begin ----------------
        $(".menu").mouseenter(function(){
            $(".list").slideDown(1000);
            
        })
        $(".menu").mouseleave(function(){
             $(".list").slideUp(1000);
            
        })
         //-------------- End --------------------

     })
    </script>
</body>
</html>

第4关:jQuery动画效果——自定义动画

<!doctype html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>Document</title>
	<script src="https://code.jquery.com/jquery-3.3.1.min.js"></script>

	<style>
	.container{
		width: 100px;
        height: 200px;
        margin: 20px auto;
        position:relative;
	}
    button{
    	position: absolute;
        left: 30px;
        bottom: 10px;
    }
    img{
        width: 30px;
        height: 30px;
        position: absolute;
        left: 36px;
        bottom: 36px;
        display: none;
    }

	</style>
</head>
<body>
    <div class="container">
    	<button class="btn">点赞</button>
    </div>

   <script>
    $(function(){
         $(".btn").click(function(){
            //向contianer里插入DOM元素 img 标签,每点击一次,插入一张图片。
            var dom = '<img class="love" src="https://www.educoder.net/attachments/download/206509" alt="爱心">';
            $(".container").append(dom);

            //--------- Begin ----------
            $(".love").show().animate({bottom:"+=120px",opacity:"0"},1500);

             
            //--------- End ------------
         })
    })

   </script>
</body>
</html>

  • 1
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值