關於我昨晚問的問題,只有一個答案,我有一個關於jQuery動畫的問題。如果我想在某個時候退出一個動畫,由任意事件決定,並以不同的速度開始另一個動畫,是否有任何方法可以使這種變化不明顯?平滑地改變jQuery動畫
換句話說,如果動畫在4000ms開始,那麼用戶移動鼠標並停止第一個動畫,並且第二個動畫開始,這個在2000ms,是否有辦法避免在第二個動畫之前出現可怕的暫停動畫開始?
我在元素上使用.stop(true)來停止當前正在運行的動畫,然後開始第二個動畫,但它不起作用,.clearQueue()僅在事件完成時觸發。
按照要求,下面的代碼:
$(document).ready(function(){
$('#innerMainbottom').hover(function(){
$('#innerMainbottom').mousemove(function(e){
var mouseX = e.pageX-$(this).offset().left,
width = $(this).innerWidth(), // the width is 1000, but the container to move is 1600, hidden by overflow:hidden
speed = (width-mouseX)*10,
sliderCont = $('#sliderCont'); // this is the container I want to move
if(mouseX>=510&&mouseX<=960){ // do this if the user hovers to the right half of the container
moverRight(mouseX,width,speed,sliderCont);
}
else if(mouseX>=0&&mouseX<=460){ // do this if the user hovers to the left half of the container
moverLeft(mouseX,width,speed,sliderCont);
}
else if(mouseX>460&&mouseX<510){ // stop altogether if the user hovers in the centre of the container, emulating a pausing effect
$('#sliderCont').stop(true);
}
});
function moverRight(mX,w,s,sC){
$(sC).stop(true).animate({'left':-1600+'px'},s);
}
function moverLeft(mX,w,s,sC){
$(sC).stop(true).animate({'left':0+'px'},s);
}
},function(){
$('#sliderCont').stop(true).animate({'left':0+'px'},'normal');
});
});
你可以發佈代碼來看看你正在描述這個生澀的舉動嗎 – amosrivera 2011-03-04 20:03:05
發表。 :) 提前致謝! :D – Tom 2011-03-04 20:27:21