Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Detect mouse hover on page load with jQuery

I wanted to detect whether the mouse was over an element when the web page was loaded. It appears this is not possible with jQuery - mouseover, hover etc. require a mouse move; as does getting the current mouse position (to compare with element bounds).

I have not seen this specific question asked, but have seen people saying the various bits of this aren't possible...

like image 453
Ian Grainger Avatar asked Jul 05 '11 16:07

Ian Grainger


1 Answers

My solution: add a new CSS value with the hover pseudoselector, then test for that. This seems to only work sometimes, however.

CSS:

#el:hover {background-color: transparent; }

jQuery:

if ($('#el').css('background-color') == 'transparent')
like image 107
Ian Grainger Avatar answered Sep 30 '22 16:09

Ian Grainger