javascript - How can I get jQuery to wait a second before closing my sliding menu? -


this question has answer here:

i tried using settimeout broke things. here code:

$(document).ready(function() {     $('.menu-item-has-children').hover(         function() {             $(this).children('.sub-menu').slidedown(400);         },         function() {             $(this).children('.sub-menu').slideup(400);         }     ); }); // end ready 

i'd 1 second pause before .slideup. help?

you can use delay:

set timer delay execution of subsequent items in queue.

$(document).ready(function() {     $('.menu-item-has-children').hover(         function() {             $(this).children('.sub-menu').delay(1000).slidedown(400);         },         function() {             $(this).children('.sub-menu').delay(1000).slideup(400);         }     ); }); // end ready 

docs: https://api.jquery.com/delay/


Comments