標籤:樣式 cli class nbsp height box obj scroll 透明度
用於建立自訂動畫的函數。
傳回值:jQuery animate(params, [duration], [easing], [callback])
如果使用的是“hide”、“show”或“toggle”這樣的字串值,則會為該屬性調用預設的動畫形式。paramsOptions一組包
含作為動畫屬性和終值的樣式屬性和及其值的集合
params 對象{},注意:所有指定的屬性必須用駱駝形式,比如用marginLeft代替margin-left,如果使用的是“hide”、
“show”或“toggle”這樣的字串值,則會為該屬性調用預設的動畫形式。
duration (可選)三種預定速度之一的字串("slow", "normal", or "fast")或表示動畫時間長度的毫秒數值(如:1000)
easing (可選)String要使用的擦除效果的名稱(需要外掛程式支援).預設jQuery提供"linear" 和 "swing"
callback (可選)Function在動畫完成時執行的函數
0.停止動畫
?
| 123 |
if($(‘.swaplist,.mainlist‘).is(‘:animated‘)){ $(‘.swaplist,.mainlist‘).stop(true,true);} |
animate執行個體:
1.點擊按鈕後div元素的幾個不同屬性一同變化
?
| 12345678 |
$("#go").click(function () { $("#block").animate({ width: "90%", height: "100%", fontSize: "10em", borderWidth: 10 }, 1000);}); |
2.讓指定元素左右移動
?
| 123456 |
$("#right").click(function () { $(".block").animate({ left: ‘+50px‘ }, "slow");});$("#left").click(function () { $(".block").animate({ left: ‘-50px‘ }, "slow");}); |
3.在600毫秒內切換段落的高度和透明度
?
| 123 |
$("p").animate({ height: ‘toggle‘, opacity: ‘toggle‘}, "slow"); |
4.用500毫秒將段落移到left為50的地方並且完全清晰顯示出來(透明度為1)
?
| 123 |
$("p").animate({ left: 50, opacity: ‘show‘}, 500); |
5.切換顯示隱藏
?
| 1234567891011 |
$(".box h3").toggle(function(){ $(this).next(".text").animate({height: ‘toggle‘, opacity: ‘toggle‘}, "slow"); $(this).addClass("arrow"); return false; },function(){ $(this).next(".text").animate({height: ‘toggle‘, opacity: ‘toggle‘}, "slow"); $(this).removeClass("arrow"); return false; }); }); |
?
| 12345 |
//滾動焦點$(window).scroll(function () { //當前視窗的滾動事件var winTop = $(window).scrollTop(); //擷取當前視窗的大小var objTop = $("#obj1").offset().top; //擷取當前對象的x座標}); |
jQuery動畫animate方法使用介紹