Jquery : How to load a function after some interval or after end of another function or event
I need to run a function 'setNotifications()' after a timed delay or at the end of completio开发者_运维问答n of the previous animation('#topannounce' animation).But jQuery is not running the 'setNotifications()'after the animation. What should I do? or is there a better way to run the function?Plz hlp.Thanx.
Here is the jQuery I have.
$('a#resetbtn').bind('click', function(){
//setNotifications();
$.cookie('notificationBar', 'open');
//$('#topannounce').animate({opacity: 1.0}, 3000).fadeIn('slow');
$('#topannounce').fadeIn('slow');
setNotifications();
});
function setNotifications() {
alert("load:setNotifications...");
}
Actually there is no real error in your code, it should work and you should see a messagebox alerting, but that should happen instantly when you click the anchor.
If you want the alert to appear AFTER the fadeIn, use the callback
, like:
$('a#resetbtn').bind('click', function(){
//setNotifications();
$.cookie('notificationBar', 'open');
//$('#topannounce').animate({opacity: 1.0}, 3000).fadeIn('slow');
$('#topannounce').fadeIn('slow', setNotifications);
});
function setNotifications() {
alert("load:setNotifications...");
}
精彩评论