jQuery動畫animate方法使用介紹

來源:互聯網
上載者:User

標籤: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;     }); }); 

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.