Detect mouse hover on page load with jQuery

前端 未结 5 1614
渐次进展
渐次进展 2021-01-19 04:01

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 mo

5条回答
  •  半阙折子戏
    2021-01-19 04:11

    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')
    

提交回复
热议问题