Jon Snow's papa Jon Snow's papa - 4 months ago 22
jQuery Question

Jquery wait 3 seconds after mouseover

I have got this jquery code

$(".y_e").mouseover(function(){
$(this).children(".Photopreview").show("fast");
$(this).mouseleave(function(){
$(this).children(".Photopreview").hide("fast");
})
});


and this html

<div class="y_e">
<div class="Photopreview">
<img src="../uploads/a.jpg"/>
<div class="Arrow_down" ></div>
</div>
</div>


How can i wait 3 seconds after user mouseovers on y_e?

Answer

You can use "delay" jquery method like the following code

$(".y_e").mouseover(function(){
    $(this).children(".Photopreview").stop(true,true).delay(3000).show("fast");
});
$(this).mouseleave(function(){
    $(this).children(".Photopreview").stop(true,true).hide("fast");
});

Note: don't register event listener inside other event listener, because this will register multiple listeners for same event type.