Close the closing div; if you point at him

as shown below, if the user hovers over the div, then how to stop the erosion of the div? and if it doesn’t hover over a div, then it fades regardless of the time set for.?

below is the code I'm using .... for fadein and fadeout:

 $("#success").fadeOut('slow');
 $("#success").fadeIn('slow');
 $("#success").fadeTo(5000, 1).fadeOut(2000);

my div:

<div class="success"><a href="#" class="close">&times;</a>status message here...</div>

I tried this:

if ($('#success').is(':hover')) { //dont close me and reset the time ...} 

Result: enter image description here

+3
source share
1 answer

Something like that? http://jsfiddle.net/krmNY/1/

Js

var $msg = $('#dvFadeMsg'); 
var timer = null; 

function StartFadeTimer(){
    timer = setTimeout(function(){
        $msg.fadeOut('slow');
    }, 1500); 
}

$('#dvFadeMsg').hover(function(){
    clearTimeout(timer); 
}, function(){
    StartFadeTimer(); 
});

$msg.fadeIn('slow');
StartFadeTimer();

HTML

<div id="dvFadeMsg">Fade me if no mouse</div>​
+2
source

All Articles