Javascript mouse event not captured properly when mouse moved very fast

前端 未结 1 1632
礼貌的吻别
礼貌的吻别 2021-01-14 10:23

I am using JavaScript mouseover and mouseout events when I move my mouse very quickly the events are not triggered. Can you tell me what the problem is?

Please let m

相关标签:
1条回答
  • 2021-01-14 10:38

    It depends. Javascript won't try to interpolate between "frames." Meaning, yes, if you move your mouse fast enough, one mousemove event will fire on one side of your object, and the next mousemove will fire on the other side, so mouseover and out never get fired and you're none the wiser.

    If it is absolutely critical that you capture these events, you're going to have to do a little bit of work yourself. You can hook into mousemove yourself, and for each event fire, compare the position of the mouse during the last fire, and the current fire. You'll need to do a little geometry here, but if the line created by the two points hits the bounding box of the object in question (either 4 compares based on each of the sides, or 2 compares based on an X through the box), then manually fire mouseover. And then mouseout.

    0 讨论(0)
提交回复
热议问题