Raphael JS:如何删除事件?

发布于 2024-11-14 23:51:09 字数 409 浏览 2 评论 0原文

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

Raphael文档中我发现:

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

但我无法让它工作,而且我也不理解“f”参数。

这不起作用,但是有什么作用?

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

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.

In the Raphael documentation I found :

To unbind events use the same method names with “un” prefix, i.e. element.unclick(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();
});

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

oО清风挽发oО 2024-11-21 23:51:09

好的,您要做的是将处理程序函数传递给 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/

这就是 f 的含义。您还可以使用 unhover()

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

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

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/

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/

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文