Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery delay on CSS change

Tags:

jquery

css

I'm looking to add a 300 millisecond delay to the function of this jQuery but not 100% sure where it should sit?

I understand that I need to add .delay(300) but wasn't too sure where it has to go in the code below.

$("#menu1-holder").mouseleave(function(){
    $('#menu1-holder').css('display', 'none');
});

OR... should I be using setTimeout? If so where should that be placed?

like image 206
Vince P Avatar asked Mar 15 '26 14:03

Vince P


2 Answers

$("#menu1-holder").mouseleave(function(){
var that = $(this);
setTimeout(function(){
   that.css('display', 'none');
}, 300);    
});
like image 123
Headshota Avatar answered Mar 17 '26 06:03

Headshota


You can also do like this with simple script:

$("#menu1-holder").mouseleave(function(){
    $('#menu1-holder').delay(300).css('display', 'none');
});

Check this http://api.jquery.com/delay/

like image 35
sandeep Avatar answered Mar 17 '26 06:03

sandeep



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!