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?

  • Possible duplicate of [If mouse over for over 2 seconds then show else dont?](http://stackoverflow.com/questions/11263636/if-mouse-over-for-over-2-seconds-then-show-else-dont) – Eaten by a Grue Jul 09 '16 at 17:45

3 Answers3

1

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,140
  • 5
  • 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
  • 5,029
  • 39
  • 40
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
  • 13
  • 17