jQuery之animate自定义动画

下面是对jQuery自定义动画的整理,希望可以帮助到有需要的小伙伴。
jQuery的animate()方法可以用来自定义动画方法
语法结构如下:

  1. animate(properties,duration,callback)
    properties - 动画的CSS样式,动画将根据该样式移动
    设置动画执行结束的样式属性值
    duration - 动画执行的时长,单位是毫秒
    callback - 在动画完成时执行的回调函数。
  2. animate(properties,options)
    properties - CSS的样式属性
    设置动画执行结束的样式属性值
    options - 设置动画的相关参数
    speed - 动画执行的时长,单位是毫秒
    callback - 在动画完成时执行的回调函数
    queue - 布尔值,设置是否添加到动画队列中, false表示立即开始动画
    实例:
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>animate()自定义动画</title>
    <script src="https://libs.baidu.com/jquery/2.1.1/jquery.min.js"></script>
    <style>
        #box {
            width: 200px;
            height: 200px;
            background-color: aquamarine;

            position: absolute;
        }
    </style>
</head>

<body>
    <div id="box"></div>

    <script>
  
        // $("#box").animate({
        //     width : 100,
        //     height : 100
        // },3000);

        // $("#box").animate({
        //     left : 100
        // },3000);

        $("#box").animate({
            left: 100
        }, {
            speed: 3000
        });


    </script>
</body>

</html>

最后小编要写一下细节问题:
1. 动画中 animate 的 width / height / left / top 等值没有单位 " px "
2. 动画中 animate 的 width / height / left / top 等值用逗号分隔
3. 动画中的可以写多个回调函数

在这里插入图片描述

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值