返回值:jQueryanimate(params, options)
概述
用于創(chuàng)建自定義動畫的函數(shù)。
這個函數(shù)的關鍵在于指定動畫形式及結果樣式屬性對象。這個對象中每個屬性都表示一個可以變化的樣式屬性(如“height”、“top”或“opacity”)。注意:所有指定的屬性必須用駱駝形式,比如用marginLeft代替margin-left. 而每個屬性的值表示這個樣式屬性到多少時動畫結束。如果是一個數(shù)值,樣式屬性就會從當前的值漸變到指定的值。如果使用的是“hide”、“show”或“toggle”這樣的字符串值,則會為該屬性調用默認的動畫形式。 在 jQuery 1.2 中,你可以使用 em 和 % 單位。另外,在 jQuery 1.2 中,你可以通過在屬性值前面指定 "<em>+=</em>" 或 "<em>-=</em>" 來讓元素做相對運動。
參數(shù)
paramsOptions
一組包含作為動畫屬性和終值的樣式屬性和及其值的集合
optionsOptions
一組包含動畫選項的值的集合。
選項
durationString,Number
(默認值: "normal") 三種預定速度之一的字符串("slow", "normal", or "fast")或表示動畫時長的毫秒數(shù)值(如:1000)
easingString
(默認值: "swing") 要使用的擦除效果的名稱(需要插件支持).默認jQuery提供"linear" 和 "swing".
completeFunction
在動畫完成時執(zhí)行的函數(shù)
stepCallback
queueBoolean
(默認值: true) 設定為false將使此動畫不進入動畫隊列 (jQuery 1.2中新增)
示例
描述:
第一個按鈕按了之后展示了不在隊列中的動畫。在div擴展到90%的同時也在增加字體,一旦字體改變完畢后,邊框的動畫才開始。
HTML 代碼:
<button id="go1">? Animate Block1</button>
<button id="go2">? Animate Block2</button>
<div id="block1">Block1</div><div id="block2">Block2</div>
jQuery 代碼:
$("#go1").click(function(){
$("#block1").animate( { width: "90%"}, { queue: false, duration: 5000 } )
.animate( { fontSize: '10em' } , 1000 )
.animate( { borderWidth: 5 }, 1000);
});
$("#go2").click(function(){
$("#block2").animate( { width: "90%"}, 1000 )
.animate( { fontSize: '10em' } , 1000 )
.animate( { borderWidth: 5 }, 1000);
});
描述:
第二個按鈕按了之后就是一個傳統(tǒng)的鏈式動畫,即等前一個動畫完成后,后一個動畫才會開始.
HTML 代碼:
<button id="go1">? Animate Block1</button>
<button id="go2">? Animate Block2</button>
<div id="block1">Block1</div><div id="block2">Block2</div>
jQuery 代碼:
$("#go1").click(function(){
$("#block1").animate( { width: "90%"}, { queue: false, duration: 5000 } )
.animate( { fontSize: '10em' } , 1000 )
.animate( { borderWidth: 5 }, 1000);
});
$("#go2").click(function(){
$("#block2").animate( { width: "90%"}, 1000 )
.animate( { fontSize: '10em' } , 1000 )
.animate( { borderWidth: 5 }, 1000);
});
描述:
用600毫秒切換段落的高度和透明度
jQuery 代碼:
$("p").animate({
height: 'toggle', opacity: 'toggle'
}, { duration: "slow" });
描述:
用500毫秒將段落移到left為50的地方并且完全清晰顯示出來(透明度為1)
jQuery 代碼:
$("p").animate({
left: 50, opacity: 'show'
}, { duration: 500 });
描述:
一個使用“easein”函數(shù)提供不同動畫樣式的例子。只有使用了插件來提供這個“easein”函數(shù),這個參數(shù)才起作用。
jQuery 代碼:
$("p").animate({
opacity: 'show'
}, { duration: "slow", easing: "easein" });