I have a list of several 'triggers' (<li>s
), each trigger shows a specific DIV, and each DIV has 'close' button.
Now, I want to improve the usability by adding a timer/delay to the opened/visible DIV so that after3 or 5 seconds after the user has moved his mouse away from the trigger, the opened/visible DIV fades out.
The problem I'm having right now, is that whenever I add a function with .mouseleave(), the opened/visible DIV hides as soon as the mouse leaves the trigger area.
However, if you remove the function, then the DIV stays visible and you're able to close it by clicking the close button.
Here's a FIDDLE/DEMO of my situation.
Any help would be greatly appreciated.
Thanks.
Use
setTimeout
instead ofdelay
.Working demo: http://jsfiddle.net/J7qTy/
From jQuery delay documentation:
you need a duration in the hide:
You can take a look at the docs http://api.jquery.com/delay/
update
is this what your looking for?
Thats it get rid of mouseleave listener
@locrizak's answer is right (+1). This is because
.delay()
defaults to the effects queue, but.hide()
with no parameters hides the selected elements without any effect, so the effects queue isn't involved at all.If you want to hide without any animation, just use
setTimeout
:http://jsfiddle.net/mattball/93F3k/
Last edit, I promise
Demo: http://jsfiddle.net/mattball/b2ew5/