首页 > 代码库 > JQuery动画插件Velocity.js发布:更快的动画切换速度

JQuery动画插件Velocity.js发布:更快的动画切换速度

 5月3日,Julian在其GitHub上发布了Velocity.js。Velocity.js是一款动画切换的jQuery插件,它重新实现了jQuery的$.animate()方法从而加快动画切换的速度。Velocity.js只有7k的大小,它不仅包含了$.animate()的所有功能,并且还包含了颜色切换、转换(transform)、循环、缓动、CSS切换、Scroll功能,它是jQuery、 jQuery UI、CSS变换 在动画方面的最佳组合。Velocity.js支持IE8+、Chrome、Firefox等浏览器,并支持Andriod以及IOS。Velocity.js在内部实现中使用了jQuery的$.queue()方法,因此它比 jQuery的$.animate()、$.fade()、$.delay()方法更加流畅,其性能也高于CSS的animation属性,具体原理读者可以参考这篇文章。

  Velocity.js包含两个输入参数,第一个参数用于规定产生的动画效果,第二个参数为可选参数,用于规定动画的额外选项。具体如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
$("div").velocity({
    property1: value1,
    property2: value2
}, {
    /* Default options */
    duration: 400,
    easing: "swing",
    queue: "",
    complete: null,
    loop: false,
    delay: false,
    display: false,
    mobileHA: true
});

  Velocity.js同样支持jQuery的参数简写语法:$element.velocity(propertyMap [, duration] [, easing] [, complete]):,比如:

1
2
3
$("div").velocity({ left: 100 }, 1000);
$("div").velocity({ left: 100 }, 1000, "swing");
$("div").velocity({ left: 100 }, "swing");

  Velocity.js官方宣传Velocity的目标是成为DOM中动画切换方面的领导者。读者可以从这里下载最新版本的Velocity.js,由于Velocity.js的方法签名和$.animate()一样,因此只需将方法名从animate改为velocity即可。在其官方网站给出了几个绚丽的Demo,读者可以参考学习。

 参考文档

  1. http://julian.com/research/velocity/
  2. http://davidwalsh.name/css-js-animation
  3. https://news.ycombinator.com/item?id=7663775
<iframe id="google_ads_frame2" vspace="0" height="250" marginHeight="0" src="http://googleads.g.doubleclick.net/pagead/ads?client=ca-pub-3447371224873639&output=html&h=250&slotname=8660799060&adk=1970350646&w=300&lmt=1399629938&flash=0&url=http%3A%2F%2Fwww.cnblogs.com%2Franzige%2Fp%2F3718867.html&dt=1399629939585&shv=r20140501&cbv=r20140417&saldr=sb&prev_slotnames=4356862740&correlator=1399629939509&frm=20&ga_vid=429972749.1397695120&ga_sid=1399623329&ga_hid=675558884&ga_fc=1&u_tz=480&u_his=241&u_java=1&u_h=768&u_w=1364&u_ah=740&u_aw=1364&u_cd=16&u_nplug=0&u_nmime=0&dff=tahoma&dfs=12&adx=0&ady=1200&biw=314&bih=74&eid=317150304%2C317150313&oid=3&rx=0&eae=0&docm=9&brdim=51%2C447%2C33%2C35%2C1364%2C%2C1298%2C669%2C330%2C90&vis=0&fu=0&ifi=2&xpc=jrl0mzsCkh&p=http%3A//www.cnblogs.com&dtd=47" frameBorder="0" width="300" allowTransparency="true" name="google_ads_frame2" marginWidth="0" scrolling="no" hspace="0"></iframe><iframe id="google_ads_frame3" vspace="0" height="250" marginHeight="0" src="http://googleads.g.doubleclick.net/pagead/ads?client=ca-pub-3447371224873639&output=html&h=250&slotname=8660799060&adk=1970350646&w=300&lmt=1399629938&flash=0&url=http%3A%2F%2Fwww.cnblogs.com%2Franzige%2Fp%2F3718867.html&dt=1399629939662&shv=r20140501&cbv=r20140417&saldr=sb&prev_slotnames=4356862740%2C8660799060&correlator=1399629939509&frm=20&ga_vid=429972749.1397695120&ga_sid=1399623329&ga_hid=675558884&ga_fc=1&u_tz=480&u_his=241&u_java=1&u_h=768&u_w=1364&u_ah=740&u_aw=1364&u_cd=16&u_nplug=0&u_nmime=0&dff=tahoma&dfs=12&adx=304&ady=1450&biw=314&bih=74&eid=317150304%2C317150313&oid=3&rx=0&eae=0&docm=9&brdim=51%2C447%2C33%2C35%2C1364%2C%2C1298%2C669%2C330%2C90&vis=0&fu=0&ifi=3&xpc=JConheFo9N&p=http%3A//www.cnblogs.com&dtd=98" frameBorder="0" width="300" allowTransparency="true" name="google_ads_frame3" marginWidth="0" scrolling="no" hspace="0"></iframe>