jQuery trigger mouseover function when page loads with the mouse over the element

匆匆过客 提交于 2019-12-13 13:07:31

问题


I have an ASP.NET document, with an Image element within it.
I created a mouseover function on this image element and it's working fine.
The question is:
If the mouse is ALREADY over the element when the document loads itself, the mouseover function doesn't trigger (I need to mouseout and then mouseover again in order to trigger it).
Is there any way to check in the $(document).ready function if the mouse is already on top of this element? and if yes- trigger the mouseover function.
Thanks all!


回答1:


Why don't you use the mousemove event? You could make it fire only once by setting a flag called movedOver to true, and then setting the flag to false on mouseleave




回答2:


If I understand you, try to use $('#elem').load() and hover() method.



来源:https://stackoverflow.com/questions/2903068/jquery-trigger-mouseover-function-when-page-loads-with-the-mouse-over-the-elemen

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!