211 jQuery 自定义动画:animate()

自定义动画非常强大,通过参数的传递可以模拟以上所有动画,方法为:animate() ;

​ 语法规范如下:

代码演示

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

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <script src="jquery.min.js"></script>
    <style>
        div {
            position: absolute;
            width: 200px;
            height: 200px;
            background-color: pink;
        }
    </style>
</head>

<body>
    <button>动起来</button>
    <div></div>
    <script>
        $(function() {
            $("button").click(function() {
                // 可以把第一个参数提出来,用对象保存
                $("div").animate({
                    left: 500,
                    top: 300,
                    opacity: .4,
                    width: 500
                }, 500);
            })
        })
    </script>
</body>

</html>

posted on 2020-01-16 21:46  冲啊!  阅读(113)  评论(0编辑  收藏  举报

导航