tags:

views:

42

answers:

2

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!

A: 

This code is all wrong.. perhaps you should tell us extaly what you want to acheive then we can tell you how to adjust your code. Give important details like what happens on mouse leave and enter and what animations should be fired when.

Sorry for not being more thorough in explaining whats going on. I have a popup message that fades into view to show the user a flash message. This message is currently set to slideUp in 5 seconds, but I want the ability to stop the message from sliding away if the user has his/her mouse over the popup message. When the user's mouse leaves the popup message the counter starts over.

Does that make sense?

dennismonsewicz
A: 

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!

dennismonsewicz