延迟jQuery效果,而页面加载 [英] Delay jQuery effects whilst page is loading

查看:176
本文介绍了延迟jQuery效果,而页面加载的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有code这一点:

$("#comingsoon, #1, #2, #3").hide().each(function(i) {
    $(this).delay(i * 500).slideDown(1500);
});

这基本上消失了一系列我的网页上的对象,问题是,在动画滞后可怕当在网页顶部的闪光灯横幅加载。我想耽误整个jQuery的动画约2-3秒。

Which basically fades in a series of objects on my page, problem is that the animation lags horribly when the flash banner at the top of the page is loading. I would like to delay the entire jQuery animation for about 2-3 seconds.

任何人有任何想法。

推荐答案

既然你已经使用延迟,你可以只添加一个固定的时间间隔,以你目前的可变间隔

Since you're already using delay, you could just add a fixed interval to your current variable interval:

$("#comingsoon, #1, #2, #3").hide().each(function(i) {
  $(this).delay(2500 + i*500).slideDown(1500);
});

(这2500增加了前slideDowns启动2.5秒的延迟。)

(That 2500 adds a 2.5 second delay before the slideDowns start.)

如果你想拖延的隐藏的为好,把你整个事情的延迟功能:

If you want to delay hiding as well, put your whole thing in a delayed function:

setTimeout(function() {
    $("#comingsoon, #1, #2, #3").hide().each(function(i) {
      $(this).delay(i*500).slideDown(1500);
    });
}, 2500);

直到code持续2.5秒运行甚至不会隐瞒的事情。

That won't even hide things until 2.5 seconds after that code is run.

<一个href=\"http://stackoverflow.com/questions/3874411/delay-jquery-effects-whilst-page-is-loading/3874463#3874463\">See还约翰Gietzen的回答:如果要等到所有页面内容被加载(可以是一个漫长的时间,但也许正是你想要的这里),使用窗口 负荷事件,而不是 jQuery.ready

See also John Gietzen's answer: If you want to wait until all page content is loaded (which can be a long time, but perhaps exactly what you want here), use the window load event instead of jQuery.ready.

这篇关于延迟jQuery效果,而页面加载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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