gpt4 book ai didi

events - 拉斐尔JS : how to remove events?

转载 作者:行者123 更新时间:2023-12-02 03:09:03 41 4
gpt4 key购买 nike

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

Raphael documentation我发现:

To unbind events use the same method names with “un” prefix, i.e. 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/

这就是f 的意义所在。您还可以使用unhover():

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

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

关于events - 拉斐尔JS : how to remove events?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6315456/

41 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com