mouseover/mouseenter not fired when scrolling [duplicate]
I have the fancy Apple mouse that detects finger movements such as "swipe" and "scroll".
Leaving the cursor fixed on the screen, but using my finger to scroll down my page, the cursor (although fixed) naturally moves over different elements, 开发者_运维知识库because the elements are moving themselves.
My problem is that when doing that, the appropriate mouseover/mouseenter callbacks don't get called when he mouse cursor is directly above them.
How can I solve this problem?
Most browsers that I've used don't fire mouse events when the page scrolls. You could try listening to the onscroll
event and using document.elementFromPoint
to determine what element has moved underneath the mouse cursor when the onscroll
event fires.
Jquery's mousemove method is a nice solution here as it does get triggered when the mouse is rolled into an element as you scroll, even while the mouse has remained static.
You could even trigger the mouseenter event on mousemove as long as you include some kind of flag/state-check to ensure your mouseenter code doesn't get executed repeatedly on mousemove.
I dont think you can... short of having a function that runs on a timer to check the position of the mouse against the elements, but the performance hit on that would be astronomical to say the least. Probably should file a bug report with the browser manufacturer and check other browsers to see if the behavior is replicated - Which I'm guessing it will because dont think any browser will fire a mouseover/mouseenter event if the mouse was not physically moved.
精彩评论