jQuery animate easing使用方法圖文詳解
從jQuery API 文檔中可以知道,jQuery自定義動(dòng)畫的函數(shù).animate( properties [, duration] [, easing] [, complete] )有四個(gè)參數(shù):
• properties:一組包含作為動(dòng)畫屬性和終值的樣式屬性和及其值的集合
• duration(可選):動(dòng)畫執(zhí)行時(shí)間,其值可以是三種預(yù)定速度之一的字符串("slow", "normal", or "fast")或表示動(dòng)畫時(shí)長(zhǎng)的毫秒數(shù)值(如:1000)
• easing(可選):要使用的過(guò)渡效果的名稱,如:"linear" 或"swing"
• complete(可選):在動(dòng)畫完成時(shí)執(zhí)行的函數(shù)
其中參數(shù)easing默認(rèn)有兩個(gè)效果:"linear"和"swing",如果需要更多效果就要插件支持了,jQuery Easing Plugin提供了像"easeOutExpo"、"easeOutBounce"等30多種效果,大家可以點(diǎn)擊這里去看每一種easing的演示效果,下面詳細(xì)介紹下其使用方法及每種easing的曲線圖。
jQuery easing 使用方法
首先,項(xiàng)目中如果需要使用特殊的動(dòng)畫效果,則需要在引入jQuery之后引入jquery.easing.1.3.js
<script type="text/javascript" src="http://code.jquery.com/jquery-1.8.3.js"></script> <script type="text/javascript" src="http://gsgd.co.uk/sandbox/jquery/easing/jquery.easing.1.3.js"></script>
引入之后,easing參數(shù)可選的值就有以下32種:
1. linear
2. swing
3. easeInQuad
4. easeOutQuad
5. easeInOutQuad
6. easeInCubic
7. easeOutCubic
8. easeInOutCubic
9. easeInQuart
10. easeOutQuart
11. easeInOutQuart
12. easeInQuint
13. easeOutQuint
14. easeInOutQuint
15. easeInExpo
16. easeOutExpo
17. easeInOutExpo
18. easeInSine
19. easeOutSine
20. easeInOutSine
21. easeInCirc
22. easeOutCirc
23. easeInOutCirc
24. easeInElastic
25. easeOutElastic
26. easeInOutElastic
27. easeInBack
28. easeOutBack
29. easeInOutBack
30. easeInBounce
31. easeOutBounce
32. easeInOutBounce
當(dāng) 然一般一個(gè)項(xiàng)目中不可能會(huì)用到這么多效果,為了減少代碼冗余,必要時(shí)可以不用引入整個(gè)jquery.easing.1.3.js,我們可以只把我們需要的 幾種easing放入Javascript文件中,如項(xiàng)目中只用到"easeOutExpo"和"easeOutBounce"兩種效果,只需要下面的代 碼就可以了
jQuery.extend( jQuery.easing,
{
easeOutExpo: function (x, t, b, c, d) {
return (t==d) ? b+c : c * (-Math.pow(2, -10 * t/d) + 1) + b;
},
easeOutBounce: function (x, t, b, c, d) {
if ((t/=d) < (1/2.75)) {
return c*(7.5625*t*t) + b;
} else if (t < (2/2.75)) {
return c*(7.5625*(t-=(1.5/2.75))*t + .75) + b;
} else if (t < (2.5/2.75)) {
return c*(7.5625*(t-=(2.25/2.75))*t + .9375) + b;
} else {
return c*(7.5625*(t-=(2.625/2.75))*t + .984375) + b;
}
},
});
使用jQuery自定義動(dòng)畫函數(shù)animate來(lái)指定easing效果,如自定義一種類彈簧效果的動(dòng)畫:
$(myElement).animate({
top: 500,
opacity: 1
}, 1000, 'easeOutBounce');
值得一提的是jQuery 1.4版本中對(duì)animate()方法,easing的方法進(jìn)行了擴(kuò)展,支持為每個(gè)屬性指定easing方法,詳細(xì)請(qǐng)參考這里,如:
//第一種寫法
$(myElement).animate({
left: [500, 'swing'],
top: [200, 'easeOutBounce']
});
//第二種寫法
$(myElement).animate({
left: 500,
top: 200
}, {
specialEasing: {
left: 'swing',
top: 'easeOutBounce'
}
});
使用jQuery內(nèi)置動(dòng)畫函數(shù)如slideUp()、slideDown()等來(lái)指定easing效果,以下兩種方法都可以:
$(myElement).slideUp(1000, method, callback});
$(myElement).slideUp({
duration: 1000,
easing: method,
complete: callback
});
jQuery easing 圖解
以下圖解可以讓你更容易理解每一種easing的效果

以上所述是小編給大家介紹的jQuery animate easing使用方法詳解的相關(guān)知識(shí),希望對(duì)大家有所幫助,如果大家有任何疑問(wèn)請(qǐng)給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對(duì)腳本之家網(wǎng)站的支持!
- jQuery中animate的幾種用法與注意事項(xiàng)
- jQuery中使用animate自定義動(dòng)畫的方法
- 深入理解jquery自定義動(dòng)畫animate()
- 分享有關(guān)jQuery中animate、slide、fade等動(dòng)畫的連續(xù)觸發(fā)、滯后反復(fù)執(zhí)行的bug
- 基于jquery animate操作css樣式屬性小結(jié)
- jQuery插件animateSlide制作多點(diǎn)滑動(dòng)幻燈片
- jQuery中animate動(dòng)畫第二次點(diǎn)擊事件沒(méi)反應(yīng)
- jQuery的animate函數(shù)實(shí)現(xiàn)圖文切換動(dòng)畫效果
- js實(shí)現(xiàn)類似jquery里animate動(dòng)畫效果的方法
- jquery使用animate方法實(shí)現(xiàn)控制元素移動(dòng)
- jQuery實(shí)現(xiàn)立體式數(shù)字動(dòng)態(tài)增加(animate方法)
相關(guān)文章
IE8下Jquery獲取select選中的值post到后臺(tái)報(bào)錯(cuò)問(wèn)題
IE8下出現(xiàn)的問(wèn)題是直接將selectedValue post發(fā)送到后臺(tái),后臺(tái)接收時(shí)會(huì)報(bào)錯(cuò),這是因?yàn)镮E8下selectedValue當(dāng)成了數(shù)組,后臺(tái)無(wú)法識(shí)別2014-07-07
基于jQuery選擇器之表單對(duì)象屬性篩選選擇器的實(shí)例
下面小編就為大家?guī)?lái)一篇jQuery選擇器之表單對(duì)象屬性篩選選擇器實(shí)例。小編覺(jué)得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2017-09-09
jQuery學(xué)習(xí)筆記之jQuery.extend(),jQuery.fn.extend()分析
給jQuery做過(guò)擴(kuò)展或者制作過(guò)jQuery插件的人這兩個(gè)方法東西可能不陌生. jQuery.extend([deep],target,object1,,object2...[objectN]) jQuery.fn.extend([deep],target,object1,,object2...[objectN]) 這兩個(gè)屬性都是用于合并兩個(gè)或多個(gè)對(duì)象的屬性到target對(duì)象.2014-06-06
jquery下拉select控件操作方法分享(jquery操作select)
這篇文章主要介紹了jquery下拉select控件操作方法分享(jquery操作select),需要的朋友可以參考下2014-03-03
jQuery側(cè)邊欄隨窗口滾動(dòng)實(shí)現(xiàn)方法
jQuery側(cè)邊欄隨窗口滾動(dòng)實(shí)現(xiàn)方法,需要的朋友可以參考一下2013-03-03
jQuery簡(jiǎn)單實(shí)現(xiàn)點(diǎn)擊文本框復(fù)制內(nèi)容到剪貼板上的方法
這篇文章主要介紹了jQuery簡(jiǎn)單實(shí)現(xiàn)點(diǎn)擊文本框復(fù)制內(nèi)容到剪貼板上的方法,涉及jQuery針對(duì)瀏覽器的判定與剪貼板的讀寫操作技巧,需要的朋友可以參考下2016-08-08
jQuery學(xué)習(xí)筆記 操作jQuery對(duì)象 文檔處理
HTML文檔的層次關(guān)系是樹型的,每個(gè)標(biāo)簽可視為樹的各個(gè)節(jié)點(diǎn)。若操作jQuery對(duì)象,使得HTML文檔的結(jié)構(gòu)發(fā)生了改變,就叫做文檔處理2012-09-09

