jQuery delay()-如何停止它? [英] jQuery delay() - how to stop it?

查看:76
本文介绍了jQuery delay()-如何停止它?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经尝试过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必须在重复该功能之前对其进行保护,但这也无法正常工作.问题是当我快速更换幻灯片时,因为该重置不会停止所有操作,并且会开始执行我不执行的操作想要参与(例如将图片更改为其他图片).

解决方案

从jQuery 延迟页:

.delay()方法最适合在排队的jQuery之间进行延迟 效果.因为它是有限的,例如,它没有提供一种方法来 取消延迟-.delay()不能替代JavaScript的本机 setTimeout函数,可能更适合某些用途 案例.

看看 doTimeout 插件;可能就是您要寻找的.

我希望这会有所帮助!

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).

解决方案

From the jQuery delay page:

The .delay() method is best for delaying between queued jQuery effects. Because it is limited—it doesn't, for example, offer a way to cancel the delay—.delay() is not a replacement for JavaScript's native setTimeout function, which may be more appropriate for certain use cases.

Take a look at the doTimeout plugin; it may be what you are looking for.

I hope this helps!

这篇关于jQuery delay()-如何停止它?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆