jQuery动画

jQuery动画:

方法:
show hide toggle:显示 隐藏 切换
<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>Title</title>
        <style>
            #d1{
                width: 200px;
                height: 200px;
                background-color: yellow;
                /*让元素不显示*/
                display: none;
            }
            #d2{
                width: 200px;
                height: 200px;
                background-color: green;
            }
        </style>
        <script type="text/javascript" src="jquery.min.js"></script>
        <script>
            function fun1() {
                /*三个参数,完成时间  动画效果  动画完成后执行的方法,不用的参数可以不写*/
                $("#d1").show(2000)
                $("#d2").hide(3000);
            }
            function fun2() {
                $("#d1").hide(2000)
                $("#d2").show(3000);
            }
            function fun3() {
                /*切换*/
                $("#d1").toggle(3000)
                $("#d2").toggle(3000);
            }
        </script>
    </head>
    <body>
        <div id="d1"></div>
        <div id="d2"></div>
        <input type="button" value="show" onclick="fun1()" />
        <input type="button" value="hide" onclick="fun2()" />
        <input type="button" value="toggle" onclick="fun3()" />
    </body>
</html>
slideDown slideUp slideToggle 上下显示 上下隐藏 上下切换
<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>Title</title>
        <style>
            #d1{
                width: 200px;
                height: 200px;
                background-color: yellow;
                /*让元素不显示*/
                display: none;
            }
            #d2{
                width: 200px;
                height: 200px;
                background-color: green;
            }
        </style>
        <script type="text/javascript" src="jquery.min.js"></script>
        <script>
            function fun1() {
                /*三个参数,完成时间  动画效果  动画完成后执行的方法,不用的参数可以不写*/
                $("#d1").slideDown(2000)
                $("#d2").slideUp(3000);
            }
            function fun2() {
                $("#d1").slideUp(2000)
                $("#d2").slideDown(3000);
            }
            function fun3() {
                /*切换*/
                $("#d1").slideToggle(3000)
                $("#d2").slideToggle(3000);
            }
        </script>
    </head>
    <body>
        <div id="d1"></div>
        <div id="d2"></div>
        <input type="button" value="show" onclick="fun1()" />
        <input type="button" value="hide" onclick="fun2()" />
        <input type="button" value="toggle" onclick="fun3()" />
    </body>
</html>
fadeIn fadeOut fadeToggle fadeTo 渐变显示 渐变隐藏 渐变切换 渐变到一定程度
<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>Title</title>
        <style>
            #d1{
                width: 200px;
                height: 200px;
                background-color: yellow;
                /*让元素不显示*/
                display: none;
            }
            #d2{
                width: 200px;
                height: 200px;
                background-color: green;
            }
        </style>
        <script type="text/javascript" src="jquery.min.js"></script>
        <script>
            function fun1() {
                /*三个参数,完成时间  动画效果  动画完成后执行的方法,不用的参数可以不写*/
                $("#d1").fadeIn(2000)
                $("#d2").fadeOut(3000);
            }
            function fun2() {
                $("#d1").fadeOut(2000)
                $("#d2").fadeIn(3000);
            }
            function fun3() {
                /*切换*/
                $("#d1").fadeToggle(3000)
                $("#d2").fadeToggle(3000);
            }
        </script>
    </head>
    <body>
        <div id="d1"></div>
        <div id="d2"></div>
        <div id="d3"></div>
        <input type="button" value="show" onclick="fun1()" />
        <input type="button" value="hide" onclick="fun2()" />
        <input type="button" value="toggle" onclick="fun3()" />

    </body>
</html>
animate :自定义动画,参数:动画变化的方法,变化的时间,动画结束后执行的方法
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <style>
        #d1{
            width: 100px;
            height: 100px;
            margin: 0px auto;
        }
        #d1 img{
            width: 100px;
            height: 100px;
        }
    </style>
    <script type="text/javascript" src="jquery.min.js"></script>
    <script>
        $(function () {
            setInterval(function () {
                $('#d1').animate({
                    width:'50px',
                    height:'50px',
                    opacity:0.2
                },500)
                $('#d1 img').animate({
                    width:'50px',
                    height:'50px',
                    opacity:0.2
                },500)

                $('#d1').animate({
                    width:'100px',
                    height:'100px',
                    opacity:1
                },500)
                $('#d1 img').animate({
                    width:'100px',
                    height:'100px',
                    opacity:1
                },500)
            },1000)
        })
    </script>
</head>
<body>
    <div id='d1'>
        <img src="../img/b.jpg" />
    </div>

</body>
</html>
迭代遍历的方法:
<script>
    $(function(){
        var $lis =$('li')
        /*遍历所有元素的方法*/
        /*
				 each每拿出一个元素 都会执行一次内部的function 
				 i 当前元素的索引
				 e 当前元素 DOM对象
				 * 
				 * */
        $lis.each(function (i,e){
            console.info(i+'>>>'+$(e).text())
        })


        $.each($lis,function (i,e){
            console.info(i+'>>>'+$(e).text())
        })
    })
</script>
  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值