如何解决Raphael JS:如何删除事件?
| 我使用Raphael .mouseover()和.mouseout()事件来突出显示SVG中的某些元素。 这可以正常工作,但是在单击元素后,我希望它停止突出显示。 在Raphael文档中,我发现: 要取消绑定事件,请使用带有“ un”前缀的相同方法名称,即element.unclick(f);。 但是我无法使它正常工作,而且我也不理解\'f \'参数。 这行不通,但是怎么办?obj.click( function() {
this.unmouseover();
});
解决方法
好的,您要做的就是将处理函数传递给
unmouseover
请求:
// Creates canvas 320 × 200 at 10,50
var paper = Raphael(10,50,320,200);
// Creates circle at x = 50,y = 40,with radius 10
var circle = paper.circle(50,40,10);
// Sets the fill attribute of the circle to red (#f00)
circle.attr(\"fill\",\"#f00\");
// Sets the stroke attribute of the circle to white
circle.attr(\"stroke\",\"#fff\");
var mouseover = function (event) {
this.attr({fill: \"yellow\"});
}
var mouseout = function (event) {
this.attr({fill: \"red\"});
}
circle.hover(mouseover,mouseout);
circle.click(function (event) {
this.attr({fill: \"blue\"});
this.unmouseover(mouseover);
this.unmouseout(mouseout);
});
http://jsfiddle.net/GexHj/1/
那就是ѭ3的意思。您也可以使用unhover()
:
circle.click(function (event) {
this.attr({fill: \"blue\"});
this.unhover(mouseover,mouseout);
});
http://jsfiddle.net/GexHj/2/
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。