Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery: is mouse still over the element?

I would like to be able to detect if the mouse is still over the element in the following scenario:

  1. If mouseover then sleep for a few seconds.
  2. Once done sleeping check of the mouse is still over the same element.
  3. If true then do something.

How can I achieve #2?

Thank you.

like image 533
thedp Avatar asked Dec 07 '09 00:12

thedp


1 Answers

This seems to work (http://jsbin.com/uvoqe)

$("#hello").hover( function () {
  $(this).data('timeout', setTimeout( function () {

    alert('You have been hovering this element for 1000ms');

  }, 1000));
}, function () {

  clearTimeout($(this).data('timeout'));

});
like image 123
Vilius Paulauskas Avatar answered Sep 29 '22 15:09

Vilius Paulauskas