標籤:blog java 使用 width io cti
用於建立自訂動畫的函數。
傳回值: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.停止動畫
if($(‘.swaplist,.mainlist‘).is(‘:animated‘)){ $(‘.swaplist,.mainlist‘).stop(true,true);}
animate執行個體:
1.點擊按鈕後div元素的幾個不同屬性一同變化
$("#go").click(function () { $("#block").animate({ width: "90%", height: "100%", fontSize: "10em", borderWidth: 10 }, 1000);});
2.讓指定元素左右移動
$("#right").click(function () { $(".block").animate({ left: ‘+50px‘ }, "slow");});$("#left").click(function () { $(".block").animate({ left: ‘-50px‘ }, "slow");});
3.在600毫秒內切換段落的高度和透明度
$("p").animate({ height: ‘toggle‘, opacity: ‘toggle‘}, "slow");
4.用500毫秒將段落移到left為50的地方並且完全清晰顯示出來(透明度為1)
$("p").animate({ left: 50, opacity: ‘show‘}, 500);
5.切換顯示隱藏
$(".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; }); });