Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Halt closing the div; if hover over it

Tags:

jquery

as shown below, if the user hover over the div then how to halt the fade out div? and if the is not hover the div then fadeout whatever the time is set to.?

below is the code i am 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

like image 734
Nick Kahn Avatar asked Dec 06 '25 14:12

Nick Kahn


1 Answers

Something like this? 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>​
like image 166
Brandon Boone Avatar answered Dec 08 '25 17:12

Brandon Boone



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!