jquery.easing的使用

下载地址:http://www.jb51.net/jiaoben/32922.htmljavascript

基本语法:easing:格式为json,{duration:持续时间,easing:过渡效果,complete:成功后的回调函数}html

介绍:easing是jquery的一个插件,使用它能够建立更加绚丽的动画效果。java

环境:由于easing是jQuery的插件,因此必须是在引入jquery以后再引入它,以下:jquery

<script type="text/javascript" src="jquery-1.11.0.js"></script>
<script type="text/javascript" src="jquery.easing.min.js"></script>

使用:json

easing是基于animate这个函数,animate的语法:animate(params,speed,easing,fn);函数

params:一组包含做为动画属性和终值的样式属性和及其值的集合,必须为json格式动画

speed:三种预约速度之一的字符串("slow","normal", or "fast")或表示动画时长的毫秒数值(如:1000)spa

easing:过渡效果名称,默认jquery只提供"linear" 和 "swing",默认过渡效果是"swing".net

fn:动画完成时执行的函数插件

若是在没引入easing的状况下若是想改变元素的left:

html:

<div style="width:100px; height:100px; background-color:#ccc; position:absolute; left:20px;"></div>

jquery代码:

$(function (){
    $(document).click(function (){
        $("div").animate({left: "300px"}, 1000,"linear",function (){
            alert('a');
        });
    });
});

在引入easing以后animate语法:animate(params,easing)

params:一组包含做为动画属性和终值的样式属性和及其值的集合,必须为json格式

easing:格式为json,{duration:持续时间,easing:过渡效果,complete:成功后的回调函数}

例子:一样改变left值

html:

<div style="width:100px; height:100px; background-color:#ccc; position:absolute; left:20px;"></div>

jquery:

$(function (){
    $(document).click(function (){
        $("div").animate({left: "300px"},{
            duration:1000,
            easing:"easeOutBounce",
            complete:function (){
                alert("动画完成");
            }
        });
    });
});

完整代码:

<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<script type="text/javascript" src="jquery-1.11.0.js"></script>
<script type="text/javascript" src="jquery.easing.min.js"></script>
<script type="text/javascript">
$(function (){
    $(document).click(function (){
        $("div").animate({left: "300px"},{
            duration:1000,
            easing:"easeOutBounce",
            complete:function (){
                alert("动画完成");
            }
        });
    });
});
</script>
</head>
<body>
<div style="width:100px; height:100px; background-color:#ccc; position:absolute; left:20px;"></div>
</body>
</html>
相关文章
相关标签/搜索