Raphael JS:如何去除事件? [英] Raphael JS : how to remove events?

查看:157
本文介绍了Raphael JS:如何去除事件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用Raphael.mouseover()和.mouseout()事件来突出显示我的SVG中的某些元素。
这工作正常,但是点击一个元素后,我想要停止突出显示。

I use the Raphael .mouseover() and .mouseout() events to highlight some elements in my SVG. This works fine, but after I click on an element, I want it to stop highlighting.

Raphael文档我发现:


要取消绑定事件使用相同的方法名称与un前缀,即element.unclick(f);

To unbind events use the same method names with "un" prefix, i.e. element.unclick(f);

但我无法让这个工作我也不明白'f'参数。

but I can't get this to work and I also don't understand the 'f' parameter.

这不起作用,但是什么是

This doesn't work , but what does??

obj.click( function() {
  this.unmouseover();
});


推荐答案

好的,你要做的是传递处理程序功能到 unmouseover 请求:

Ok, what you have to do is pass the handler function to the unmouseover request:

// 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/

这就是 f 。您也可以使用 unhover()

That's what f is about. You can also use unhover():

circle.click(function (event) {
    this.attr({fill: "blue"});
    this.unhover(mouseover, mouseout);
});

http: //jsfiddle.net/GexHj/2/

这篇关于Raphael JS:如何去除事件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆