jQuery delay()或setTimeout()

时间:2011-10-24 21:40:28

标签: jquery javascript-events

请你帮助我...我需要在新标签页(或窗口)中打开一个链接,但只有在执行了一些函数之后。我尝试了一切,纯Javascript,jQuery,什么都行不通。 如果提供的解决方案是delay()或setTimeout(),对我来说无关紧要。 我认为延迟()的问题是它只适用于fx队列中的函数,我尝试了一些东西,但却无法让它工作。

以下是代码:

$(function(){

   $(“#playNowLink”).click(function() {

   $(‘#header’).effect(“fold”, { size: “50%” }, 1000);

   $(‘#showVideo’).delay(1100).fadeIn(‘slow’);

   // Here i would like to call ‘playNow.html’,
   //but only after 7-8 seconds


});

提前致谢

4 个答案:

答案 0 :(得分:3)

setTimeout(function(){

   //whatever the heck you want do to:

   //open window:
   window.open('new_window_url');

   //change location?
   window.location = "new_location_url";

}, 7500); //7.5 seconds

答案 1 :(得分:2)

这是你遗漏的一句话:

setTimeout(function() {window.open('playNow.html');}, 7000);

但我喜欢Matijs将其置于动画回调中的想法。

答案 2 :(得分:0)

这个javascript应该可行 - 你有什么问题吗?

setTimeout('changeLocation()',7000);
function changeLocation()
{
    window.location="playNow.html";
}

答案 3 :(得分:0)

使用.fadeIn()的回调,如此

.fadeIn('slow', function() { // do this after the fade in completes });

相关问题