开发者

jquery start animation when timer runs out

I am trying to run some code that will start a particular animation when my timer stops, but I am stuck on trying to get it started.

Code:

if($('#popup_msg').length) {
  var timer = 0;
  $('#popup_msg').bind({
   mouseenter: function() {
    timer = 0;
    console.log(timer);
   },
   mouseleave: function(){
    timer += 100;
    console.log(timer);
   }
  });

  timer += 100;

  console.log(timer);

  if(timer == 5000) {
   $('#popup_msg').delay(5000).slideUp();
  }
 }

Thanks in advance for 开发者_开发知识库the help!


I was able to figure it out using the following code

$('#popup_msg').prepend('<p>Hello World</p>').slideDown('slow', function(){
                var t = $(this);
                t.mouseenter(function(){
                    t.stop();
                }).mouseleave(function(){
                    t.delay(5000).slideUp();
                });
            }).delay(5000).slideUp();

if you know of a better way of doing this, please let me know!

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜