jQuery延迟() - 如何停止它?
我已经尝试过 stop(true,true)、stop(true) 和clearQueue();但这行不通。
我在快速更换幻灯片时遇到问题,我已经有一些必须重置所有内容的功能,但它不起作用。
function reset(){
$('div').clearQueue();
$('#img').html('').css({'left':0,'right':0,'opacity':1,'z-index':1});
$('#img2').html('').css({'left':0,'right':0,'opacity':1,'z-index':1});
$('#place').html('');$('#place').html('<div id="img"></div><div id="img2"></div>');
}
但我认为这不会停止(或删除)动画上的delay() 函数。所以我不知道是否不必使用 setTimeout 函数。
这是一段动画脚本:
reset();
actual_slide=2;
$('#img').html('<img src="'+image[4]+'" alt="Obrázek">').css({'opacity':0,'z-index':2}).delay(time_delay/5).fadeTo(time_fast,1).delay(time_delay*2).fadeTo(time_fast,0);
$('#img2').html('<img src="'+image[3]+'" alt="Obrázek">').css({'opacity':'0','top':0}).fadeTo(time_fast,1).animate({'top':'-495'},time_delay*3,function(){
if(actual_slide==2){$('#img2').css({'top':0}).fadeTo(time_fast*2,0).html('');}else{reset();}
if(actual_slide==2){$('#img').html('<img src="'+image[3]+'" id="1" alt="Obrázek">').fadeTo(time_fast*2,'1').css({'left':-300,'top':-700}).animate({'left':-900,'top':-700},time_delay*2);}else{reset();}
if(actual_slide==2){$('#1').css({'width':1365,'height':1200}).animate({'width':1665,'height':1400},time_delay*2);}else{reset();}
});
在重复该功能之前,actual_slide必须保护它,但这也不起作用..问题是当我快速更改幻灯片时,因为重置不会停止一切,并且它开始做一些事情我不想加入(比如将图片更改为其他图片)。
I already tried stop(true,true), stop(true) and clearQueue(); but this doesn't work.
I have problem with fast changing slides, i already have some function what have to reset everything, but it doesn't work.
function reset(){
$('div').clearQueue();
$('#img').html('').css({'left':0,'right':0,'opacity':1,'z-index':1});
$('#img2').html('').css({'left':0,'right':0,'opacity':1,'z-index':1});
$('#place').html('');$('#place').html('<div id="img"></div><div id="img2"></div>');
}
But i thing this doesn't stop (or delete) delay() function on animations. So I don't know if i don't have to use setTimeout function.
Here is piece of animation script:
reset();
actual_slide=2;
$('#img').html('<img src="'+image[4]+'" alt="Obrázek">').css({'opacity':0,'z-index':2}).delay(time_delay/5).fadeTo(time_fast,1).delay(time_delay*2).fadeTo(time_fast,0);
$('#img2').html('<img src="'+image[3]+'" alt="Obrázek">').css({'opacity':'0','top':0}).fadeTo(time_fast,1).animate({'top':'-495'},time_delay*3,function(){
if(actual_slide==2){$('#img2').css({'top':0}).fadeTo(time_fast*2,0).html('');}else{reset();}
if(actual_slide==2){$('#img').html('<img src="'+image[3]+'" id="1" alt="Obrázek">').fadeTo(time_fast*2,'1').css({'left':-300,'top':-700}).animate({'left':-900,'top':-700},time_delay*2);}else{reset();}
if(actual_slide==2){$('#1').css({'width':1365,'height':1200}).animate({'width':1665,'height':1400},time_delay*2);}else{reset();}
});
That actual_slide have to protect it before repeating that function, but that doesn't work too.. Problem is when i fast changing slides, because that reset doesn't stop everything, and it start doing things what i don't want to have in (like change picture to other and other).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您可以通过 .dequeue() 函数打破 .delay()
这里是示例
http ://jsfiddle.net/wasikuss/5288z/
//编辑:更复杂的示例提供了日志记录时间戳和清理(没有清理,多次点击
Start
是不可预测的)来证明它适用于 http://jsfiddle.net/q0058whc/
或以下版本
You can break .delay() by .dequeue() function
here is example
http://jsfiddle.net/wasikuss/5288z/
//edit: more complex example provided with logging timestamps and cleanup ( without cleanup, multiple clicks on
Start
is unpredictable ) to prove that it workshttp://jsfiddle.net/q0058whc/
or below
从 jQuery 延迟 页面:
看一下 doTimeout 插件;这可能就是您正在寻找的。
我希望这有帮助!
From the jQuery delay page:
Take a look at the doTimeout plugin; it may be what you are looking for.
I hope this helps!
通过 这篇文章 有一个非常简单的方法,那就是使用
.animate
代替.delay
Via this post there's a very simple approach, which is to use
.animate
in place of.delay
我希望用户一遍又一遍地快速重新启动动画链,有时是在动画中间。因此,我没有使用
delay()
,而是将动画设置为虚假的 css 属性{"null":1}
。这是一个简单的淡入/淡出。似乎对我有用!I wanted a user to rapidly restart an animation chain over and over again, sometimes in the middle of the animation. So instead of using
delay()
I animated to a bogus css propery{"null":1}
. Here's a simple fade-in/fade-out. Seems to have worked for me!