开发者

Raphael - event when mouse near element

开发者 https://www.devze.com 2023-04-12 05:11 出处:网络
I would like to make a mouse event that triggers when the mouse is near a Raphael element. (So I guess I would need to know the x,y position of the mouse. Any ideas开发者_运维技巧 on how this might be

I would like to make a mouse event that triggers when the mouse is near a Raphael element. (So I guess I would need to know the x,y position of the mouse. Any ideas开发者_运维技巧 on how this might be possible?

Thank you!


You could, as you suggest in the question, track the mouse position and compare it with the position of the element.

But that's doing things the hard way.

Far easier would be to exploit the mouseover or mouseenter events.

Obviously mouseenter and mouseover are only triggered when the mouse pointer actually goes over the element, rather than merely near it as per the question, but this is easily resolved by adding an invisible area around the element, and having the mouse event trigger on that.

This invisible area could be another element positioned in the same place as the Raphael element, but extending beyond it in each direction by a certain distance, or it could even be the same Raphael object, just make it a bit bigger and don't draw all the way to the edge.

Hope that helps.


Another idea is to use a very wide, transparent stroke to extend the 'hoverable' area, assuming you can make do with just the fill. Just an idea.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号