Raphael JS : mouseover/mouseout - problem with text-labels

这一生的挚爱 提交于 2019-12-08 01:38:27

问题


I use Raphael JS to create an SVG-map with area's and textlabels. I want the area to highlight when you move the mouse over it.

I have this working now, but when I move the mouse over the label (in the center of the area) the mouseout-event for that area is triggered, so the area is unhighlighted again.

Is there any way to prevent this from happening, or a workaround ?


回答1:


Create a rect with opacity set to 0 over the text and attach the event handlers on that rect. You can calculate the dimensions of the rect using getBBox() of the text.




回答2:


Creating a set via Paper#set was the approach that worked for me. e.g.:

var st = paper.set();

st.push.apply(st, vectors);  // `vectors`: my array of "hoverable" vectors
st.push(text);               // `text`:    my text vector for `vectors`

st.hover(function () {
    text.show();
}, function () {
    text.hide();
});


来源:https://stackoverflow.com/questions/6362849/raphael-js-mouseover-mouseout-problem-with-text-labels

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