admin管理员组

文章数量:1317909

Can someone assist me on how I can delay this function?

$('#customer_quote').lightbox_me({  
        centered: true, 
        closeSelect: ".close",
        onClose: function(){
            $('div.error').remove()
            }
        })  

 });

I want this lightbox to open after 7 seconds.

Can someone assist me on how I can delay this function?

$('#customer_quote').lightbox_me({  
        centered: true, 
        closeSelect: ".close",
        onClose: function(){
            $('div.error').remove()
            }
        })  

 });

I want this lightbox to open after 7 seconds.

Share Improve this question asked Aug 10, 2012 at 15:26 breezybreezy 1,9181 gold badge18 silver badges35 bronze badges 2
  • use setTimeout() electrictoolbox./using-settimeout-javascript – Carlo Moretti Commented Aug 10, 2012 at 15:29
  • 1 Additional Resource: developer.mozilla/en-US/docs/DOM/window.setTimeout – Nope Commented Aug 10, 2012 at 15:32
Add a ment  | 

5 Answers 5

Reset to default 8

Use setTimeout():

setTimeout(lightbox, 7000);

function lightbox() {
    $('#customer_quote').lightbox_me({  
            centered: true, 
            closeSelect: ".close",
            onClose: function(){
                $('div.error').remove()
                }
            })  

     });
}

Give setTimeout a shot:

setTimeout(function() {
    $('#customer_quote').lightbox_me({
        centered: true,
        closeSelect: ".close",
        onClose: function() {
            $('div.error').remove()
        }
    });
}, 7000);​
setTimeout(function(){
$('#customer_quote').lightbox_me({  
        centered: true, 
        closeSelect: ".close",
        onClose: function(){
            $('div.error').remove()
            }
        })  

 });

}, 7000);

Check this link out: To delay JavaScript function call using jQuery

Seems like you just use setTimeout with 7000

Use setTimeout.

var delayedFunction = function() {
   /* your code */
}

setTimeout(delayedFunction, 7000);

The second argument stands for the number of miliseconds.

Note also that this evokes an asynchronous event. The execution of your code will not stop at the line with setTimeout for 7 seconds.

If you want to execute another code after this delay, you must do so in delayedFunction, when the event fires.

本文标签: javascriptHow can i delay a functionStack Overflow