0

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?

3 Answers3

2

You can use setTimeout for waiting purposes.

$('.y_e').mouseover(function() {
  setTimeout(function() {
    // The stuff you want to do when your three seconds are over.
  }, 3000)
});
1sloc
  • 1,180
  • 6
  • 12
1

Try implement setTimeout with an anonymous function

$(".y_e").mouseover(function(){
    setTimeout(function() {
        $(this).children(".Photopreview").show("fast");
        $(this).mouseleave(function(){
            $(this).children(".Photopreview").hide("fast");
        })        
    }, 3000);
});
SandroMarques
  • 6,070
  • 1
  • 41
  • 46
0

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.

mdameer
  • 1,540
  • 2
  • 14
  • 17