关于我昨晚问的问题,只有一个答案,我有一个关于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