Raphael - event when mouse near element

偶尔善良 提交于 2019-12-13 16:40:55

问题


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!


回答1:


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.




回答2:


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.



来源:https://stackoverflow.com/questions/7736821/raphael-event-when-mouse-near-element

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