breezy
breezy

Reputation: 1918

How can i delay a function

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.

Upvotes: 1

Views: 403

Answers (5)

Imp
Imp

Reputation: 8609

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.

Upvotes: 1

ek_ny
ek_ny

Reputation: 10243

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

 });

}, 7000);

Upvotes: 3

Brian Ustas
Brian Ustas

Reputation: 65529

Give setTimeout a shot:

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

Upvotes: 4

Rory McCrossan
Rory McCrossan

Reputation: 337570

Use setTimeout():

setTimeout(lightbox, 7000);

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

     });
}

Upvotes: 8

MikeB
MikeB

Reputation: 2452

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

Seems like you just use setTimeout with 7000

Upvotes: 2

Related Questions