Raphael - 鼠标靠近元素时的事件 [英] Raphael - event when mouse near element
问题描述
我想做一个鼠标事件,当鼠标靠近拉斐尔元素时触发.(所以我想我需要知道鼠标的 x,y 位置.关于这可能如何实现的任何想法?
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?
谢谢!
推荐答案
您可以按照问题中的建议,跟踪鼠标位置并将其与元素的位置进行比较.
You could, as you suggest in the question, track the mouse position and compare it with the position of the element.
但这很难做到.
利用 mouseover
或 mouseenter
事件要容易得多.
Far easier would be to exploit the mouseover
or mouseenter
events.
显然 mouseenter
和 mouseover
仅在鼠标指针实际越过元素时触发,而不仅仅是按照问题靠近它,但这很容易解决在元素周围添加一个不可见区域,并在其上触发鼠标事件.
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.
这个不可见区域可能是与Raphael元素位于同一位置的另一个元素,但在每个方向超出它一定距离,或者它甚至可能是同一个Raphael对象,只需将其放大一点就可以了不要一直画到边缘.
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.
希望有所帮助.
这篇关于Raphael - 鼠标靠近元素时的事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!