Reputation: 1918
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
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
Reputation: 10243
setTimeout(function(){
$('#customer_quote').lightbox_me({
centered: true,
closeSelect: ".close",
onClose: function(){
$('div.error').remove()
}
})
});
}, 7000);
Upvotes: 3
Reputation: 65529
Give setTimeout
a shot:
setTimeout(function() {
$('#customer_quote').lightbox_me({
centered: true,
closeSelect: ".close",
onClose: function() {
$('div.error').remove()
}
});
}, 7000);
Upvotes: 4
Reputation: 337570
Use setTimeout()
:
setTimeout(lightbox, 7000);
function lightbox() {
$('#customer_quote').lightbox_me({
centered: true,
closeSelect: ".close",
onClose: function(){
$('div.error').remove()
}
})
});
}
Upvotes: 8
Reputation: 2452
Check this link out: To delay JavaScript function call using jQuery
Seems like you just use setTimeout with 7000
Upvotes: 2