標籤:style blog io ar color os sp on div
$(function(){ $(‘#input1‘).hover( function(){ $(‘.div1‘).stop() .animate({left:"+=50px"},1000) .animate({top:"+=40px"},2000); } ,function(){ $(‘.div1‘).stop() .animate({width:"+=50px"},2000) .animate({height:"+=40px"},1000) } ) })
CSS 部分
.div1{ width:300px; height:300px; border:1px solid #ccc; background: #666; position:absolute; left:30%; top:30%; margin-left:-150px; margin-top:-150px; }
html部分
<div class="div1"></div><br/><input type="button" id="input1" value="開始動畫" />
測試結果:
1.執行left時,移除滑鼠,發生第二個stop(),阻止left,執行top、width和height;
2.執行top時,移除滑鼠,發生第二個stop(),阻止top, 執行width 和 height;
3.執行left時,移除滑鼠,當未執行完top時,移入,發生第一個stop(),阻止top,按照順序執行width和height,以及新的left和top;
4.執行top時,移除滑鼠,當未執行完width時,移入,發生第一個stop(),阻止width,按順序執行height,以及新的left和top;
結論:
stop() 只能阻止上一個動畫
stop()參數測試
預設的stop(),即為stop( false , false )
在JQuery 代碼中相應位置填入,則
====> stop(true,false) 阻止一個隊列中(function(){ ... })的動畫
====> stop(false,true) 僅組織一個動畫(類似與stop()),跳到上一個動畫結束狀態
====> stop(true,true) 阻止一個隊列中的動畫,並跳到隊列末尾動畫狀態
JQuery的stop()屬性