jQuery .delay()不起作用 [英] jQuery .delay() doesn't work

查看:95
本文介绍了jQuery .delay()不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下JavaScript代码段:

I've the following JavaScript snippet:

$("#dashboard").addClass("standby").delay(3000).removeClass("standby");
$(".active").removeClass("active");
$("." + target).addClass("active");
$(".showDiv").removeClass("showDiv").addClass("hide");
$("#" + target).removeClass("hide").addClass("showDiv");

#dashboard处于 standby 时,它应该处理所有这些CSS类更改.更改之后,它应该再次显示#dashboard.因此,我在standby类的添加和删除之间设置了delay().为了查看是否有效,我添加了3sek的持续时间太长.

While #dashboard is in standby, it should handle all this CSS-Class changes. After this changes, it should display the #dashboard again. So I set delay() between the add and remove of the standby-class. To see if it works I added the too long duration of 3sek.

但这并没有延迟!为什么不呢?我没看到...

But it doesn't delay! Why it don't? I don't see it...

推荐答案

delay 仅处理动画管道中经过的动作,并且不会对像这样的即时原子操作的时间产生影响.为了延迟诸如添加或删除类之类的操作,可以使用

.delay()方法允许我们延迟队列中跟在其后的功能的执行.它可以与标准效果队列或自定义队列一起使用.

the .delay() method allows us to delay the execution of functions that follow it in the queue. It can be used with the standard effects queue or with a custom queue.

.delay()方法最适合在排队的jQuery效果之间进行延迟.由于它是有限的(例如,它没有提供消除延迟的方法)..delay()不能替代JavaScript的本机setTimeout函数,该函数可能更适合某些用例.

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.

这篇关于jQuery .delay()不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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