jQuery .delay().fadeOut取消/清除队列.如何? [英] Jquery .delay().fadeOut cancel/clear queue.. Is it possible? How?

查看:274
本文介绍了jQuery .delay().fadeOut取消/清除队列.如何?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在这里需要一些帮助. 可以取消链接延迟吗?

I need some help here.. Is it possible to cancel the chaining delay?

Mn.Base.TopBox.show = function(timedur){
    $('#element').fadeIn().delay(timedur).fadeOut();
}


Mn.Base.TopBox.cancelFadeout = function(){

}

我阅读了有关排队的信息,并尝试了一些不同的方法,但是我没有成功...

I read about queuing and tried some different approaches but I hadn't success...

    $('#element').stop();

    $('#element').queue('fx', []);


预先感谢


Thanks in advance,

佩德罗

推荐答案

不是, .delay() 不能与其他任何东西配合使用,因为计时器一直在滴答作响,并且 .dequeue() 是在结束时执行...不管您是否清除队列并添加一个新队列.

It isn't, .delay() doesn't play well with anything else since the timer keeps ticking and a .dequeue() is executed when it's up...regardless of if you cleared the queue and added a whole new one.

如果要取消,最好直接使用setTimeout(),例如:

It's better to use setTimeout() directly if you intend to cancel, for example:

Mn.Base.TopBox.show = function(timedur){
  $('#element').fadeIn(function() {
    var elem = $(this);
    $.data(this, 'timer', setTimeout(function() { elem.fadeOut(); }, timedur));
  });
}

Mn.Base.TopBox.cancelFadeout = function(){
  clearTimeout($('#element').stop().data('timer'));
}

它的作用是设置计时器,并使用 $.data() 以及何时存储它选择动画,我们都调用 .stop() 来停止正在进行的任何操作, 停止计时器.

What this does is set the timer and store it using $.data(), and when clering the animations, we're both calling .stop() to stop anything in process, and stopping that timer.

如果您要迅速触发此问题,这里仍然存在潜在问题,在这种情况下,您希望切换为存储一系列延迟并清除所有延迟.

There's still the potential here for issues if you're firing this very rapidly, in which case you'd want to switch to storing an array of delays, and clear them all.

这篇关于jQuery .delay().fadeOut取消/清除队列.如何?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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