返回值:jQueryanimate(params, options)
概述
用于創(chuàng)建自定義動(dòng)畫的函數(shù)。
這個(gè)函數(shù)的關(guān)鍵在于指定動(dòng)畫形式及結(jié)果樣式屬性對(duì)象。這個(gè)對(duì)象中每個(gè)屬性都表示一個(gè)可以變化的樣式屬性(如“height”、“top”或“opacity”)。注意:所有指定的屬性必須用駱駝形式,比如用marginLeft代替margin-left. 而每個(gè)屬性的值表示這個(gè)樣式屬性到多少時(shí)動(dòng)畫結(jié)束。如果是一個(gè)數(shù)值,樣式屬性就會(huì)從當(dāng)前的值漸變到指定的值。如果使用的是“hide”、“show”或“toggle”這樣的字符串值,則會(huì)為該屬性調(diào)用默認(rèn)的動(dòng)畫形式。 在 jQuery 1.2 中,你可以使用 em 和 % 單位。另外,在 jQuery 1.2 中,你可以通過在屬性值前面指定 "<em>+=</em>" 或 "<em>-=</em>" 來讓元素做相對(duì)運(yùn)動(dòng)。
參數(shù)
paramsOptions
一組包含作為動(dòng)畫屬性和終值的樣式屬性和及其值的集合
optionsOptions
一組包含動(dòng)畫選項(xiàng)的值的集合。
選項(xiàng)
durationString,Number
(默認(rèn)值: "normal") 三種預(yù)定速度之一的字符串("slow", "normal", or "fast")或表示動(dòng)畫時(shí)長(zhǎng)的毫秒數(shù)值(如:1000)
easingString
(默認(rèn)值: "swing") 要使用的擦除效果的名稱(需要插件支持).默認(rèn)jQuery提供"linear" 和 "swing".
completeFunction
在動(dòng)畫完成時(shí)執(zhí)行的函數(shù)
stepCallback
queueBoolean
(默認(rèn)值: true) 設(shè)定為false將使此動(dòng)畫不進(jìn)入動(dòng)畫隊(duì)列 (jQuery 1.2中新增)
示例
描述:
第一個(gè)按鈕按了之后展示了不在隊(duì)列中的動(dòng)畫。在div擴(kuò)展到90%的同時(shí)也在增加字體,一旦字體改變完畢后,邊框的動(dò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);
});
描述:
第二個(gè)按鈕按了之后就是一個(gè)傳統(tǒng)的鏈?zhǔn)絼?dòng)畫,即等前一個(gè)動(dòng)畫完成后,后一個(gè)動(dòng)畫才會(huì)開始.
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 });
描述:
一個(gè)使用“easein”函數(shù)提供不同動(dòng)畫樣式的例子。只有使用了插件來提供這個(gè)“easein”函數(shù),這個(gè)參數(shù)才起作用。
jQuery 代碼:
$("p").animate({
opacity: 'show'
}, { duration: "slow", easing: "easein" });