2

I am in a situation where I need jQuery's mouseover event to be fired when an element (in this case an image) moves under the mouse, so unlike the common situation is an element that is moving, not the mouse.

Do you know of any library/gist/technology that could help me in this sense?

I've tried with flash but with no luck, is this something than can actually be done?

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Alberto Zaccagni
  • 30,779
  • 11
  • 72
  • 106
  • what makes the element (in your case an image) moving? – Anwar Chandra Mar 08 '11 at 22:03
  • @Anwar Chandra: I move it with jQuery's `css`, assigning to it a certain `left` and `top`, recalling the "moving function" in a timeout. Right now I'm looking at html5 canvas to see if it provides something that could help me. – Alberto Zaccagni Mar 08 '11 at 22:07
  • as fas as i know, there is no such event even in HTML5. my friend created a game (with HTML5) in chrome web store that need this kind of event but can't find solution until now. – Anwar Chandra Mar 08 '11 at 22:19

2 Answers2

2

You can track mouse position by binding a handler to mousemove on the body, and calculate after every move of the image whether the pointer is over it.

Tgr
  • 27,442
  • 12
  • 81
  • 118
0

I ran across a similar issue. In my case I did a "good enough" workaround by keeping track of the time the mouse last moved and then in the mouseover handler seeing if the mouse had moved recently -- within 30ms of the current time. That way I can bail out in cases where the mouse didn't actually move, but I don't have to test the hitboxes myself -- something very hard to do right and fast, and fortunately something I can leave to the browser by doing this.

Kaganar
  • 6,540
  • 2
  • 26
  • 59
  • Also see here: http://stackoverflow.com/questions/8761730/webkit-firing-mousemove-event-unexpectedly-mouse-not-moving – Kaganar Dec 16 '13 at 23:58