jquery动画

隐藏和显示

show() 、hide()

 setTimeout(function () {
            $('#box1').hide();
            setTimeout(function () {
                $('#box1').show()
            }, 2000)
        }, 2000)

以前的版本有bug show方法不管之前元素的display是什么都直接改为block 例如show之前是inline-block也会直接改成block
新版本就不存在这个问题了;

toggle()

 var $body = $(this).siblings('.body');
            //            if ($body.is(':hidden')) {
            //                $body.show();
            //            } else {
            //                $body.hide();
            //            }

            //            $(this).siblings('.body').toggle()

这俩种写法等价

通过传参来控制

  $(this).siblings('.body').toggle('fast')
            //            $(this).siblings('.body').toggle('slow', 'linear')
            //            $(this).siblings('.body').toggle('slow', function () {
            //                console.log('动画完成');
            //            })

fadeIn 、fadeOut 、fadeToggle
通过控制元素的透明度来达到显示和隐藏

$(this).siblings('.body').fadeToggle('slow', function () {
            //                console.log('动画完成');
            //            })

fadeTo
控制元素变化到想要的透明度

  $(this).siblings('.body').fadeTo('slow', 0.5, function () {
            //                console.log('动画完成');
            //            })

slideDown 、slideUp、slideToggle
折叠效果

停止动画
stop(,)
两个参数 第一个为true 代表不仅立即停止当前动画 而且等待的其他动画也一并停止
第二个参数为true 代表直接到动画结果 而不是停止动画

finish
直接完成动画 不显示过程
这里写图片描述

jQuery.fx.off
设置为true会关闭整个页面上所有的动画

动画过渡效果
jQuery easing插件
这里写图片描述.

自定义动画
animate
这里写图片描述

animate还有一种传参情况
always 可以定义一个函数 不管动画是否完成 甚至终止 都会执行这个函数
complete 动画完成之后执行
done 和complete区别不大
duration 持续时间
easing 过渡效果
fail 动画执行失败后 执行
progress 代表每一步动画完成之后会调用这个函数
queue 代表是否在动画队列中放置动画 为false 表示立即开始 不会依次执行
start 动画开始后执行
step 一步一步调用 函数
*记住常用的就好 还有一点 这些参数不是animate专属的 之前的hide show toggle都支持这些参数

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>demo</title>
    <style>
        .panel {
            width: 300px;
            margin: 50px 0 0 50px;
            line-height: 1.8;
            text-align: center;
            font-size: 20px;
            color: #fff;
        }

        .title {
            background-color: #c7731f;
        }

        h1 {
            margin: 0;
            padding: 0;
        }

        .body {
            padding: 30px 10px;
            background-color: #5298c7;
        }
    </style>
</head>
<body>
<div class="panel">
    <div class="title">
        <!--<h1>唐诗一首</h1>-->
        <h1>aaaa</h1>
    </div>
    <div class="body">
        <!--<p>-->
        <!--白日依山尽,<br>-->
        <!--黄河入海流。<br>-->
        <!--欲穷千里目,<br>-->
        <!--更上一层楼。<br>-->
        <!--</p>-->
        <p>
            Lorem ipsum dolor sit amet, consectetur adipisicing elit. Amet eveniet numquam odio recusandae totam.
            Aliquam amet eaque esse excepturi, incidunt ipsum nisi officiis praesentium quaerat quibusdam, reiciendis
            sit vel voluptatibus!
        </p>
    </div>
</div>
<script src="../../../vendor/jquery-1.12.4.js"></script>
<script src="../../../vendor/jquery.easing.js"></script>
<script>
    $(function () {

        $('.title').click(function () {

            //            $(this).siblings('.body').animate({
            //                //                width: 200,
            //                //                height: 500,
            //
            //                //                width: '-=100',
            //                //                height: '+=200',
            //
            //                width: '50%',
            //
            //            }, 3000, function () {
            //                console.log('动画结束');
            //            })

            //            $(this).siblings('.body').animate({
            //                width: 200,
            //                height: 500
            //            }, {
            //                always: function () {
            //                    console.log('always');
            //                },
            //                complete: function () {
            //                    console.log('complete');
            //                },
            //                step: function () {
            //                    console.log('step');
            //                },
            //                progress: function () {
            //                    console.log('progress');
            //                },
            //                start: function () {
            //                    console.log('start');
            //                },
            //                duration: 3000,
            //                easing: 'linear'
            //            })

            //            var $body = $(this).siblings('.body');
            //            $body.animate({
            //                width: $body.width() * 1.5,
            //                height: $body.height() * 1.5
            //            }, 3000, function () {
            //                console.log('动画结束');
            //            })


        });

    });

</script>
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>demo</title>
    <style>
        .box {
            width: 100px;
            height: 100px;
            margin: 200px 0 0 200px;
            border-radius: 10px;
            box-shadow: 0 0 20px #999;
            line-height: 300px;
            text-align: center;
            font-size: 50px;
            color: #fff;
        }

        #box1 {
            background-color: #5298c7;
        }
    </style>
</head>
<body>
<div id="box1" class="box"></div>

<script src="../../../vendor/jquery-1.12.4.js"></script>
<script>
    $(function () {

        $('#box1').click(function () {
            var $this = $(this);
            $this
                .css({
                    position: 'absolute',
                    top: $this.position().top,
                    left: $this.position().left
                })
            //                .animate({
            //                    opacity: 'hide',
            //                    width: $this.width() * 2,
            //                    height: $this.height() * 2,
            //                    top: $this.position().top - $this.height(),//达到一种从中心扩大的效果
            //                    left: $this.position().left - $this.width()
            //                }, 3000)
        })


    });

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

动画队列
.queue() 不仅限于动画
这里写图片描述

dequeue的方式将队列的第一项拿出来执行
但是这样一次次点击才执行很麻烦

有个参数 next

 $('#box1').queue('chain', function (next) {
        //            console.log('第1次');
        //            next();
        //        }).queue('chain', function (next) {
        //            console.log('第2次');
        //            next();
        //        }).queue('chain', function (next) {
        //            console.log('第3次');
        //            next();
        //        }).queue('chain', function (next) {
        //            console.log('第4次');
        //        })

这样只需要dequeue一次就可以依次往下执行

clearQueue 直接清空队列 不执行

 $('#box1').queue('chain', function (next) {
        //            console.log('第1次');
        //            next();
        //        }).queue('chain', function (next) {
        //            console.log('第2次');
        //            next();
        //        }).queue('chain', function (next) {
        //            console.log('第3次');
        //            next();
        //        }).queue('chain', function (next) {
        //            console.log('第4次');
        //        })
1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看README.md或论文文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。 5、资源来自互联网采集,如有侵权,私聊博主删除。 6、可私信博主看论文后选择购买源代码。 1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看README.md或论文文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。 5、资源来自互联网采集,如有侵权,私聊博主删除。 6、可私信博主看论文后选择购买源代码。 1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看README.md或论文文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。 5、资源来自互联网采集,如有侵权,私聊博主删除。 6、可私信博主看论文后选择购买源代码。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值