开发者

Jquery : How to load a function after some interval or after end of another function or event

开发者 https://www.devze.com 2023-01-03 23:16 出处:网络
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 \'set

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...");
}
0

精彩评论

暂无评论...
验证码 换一张
取 消