Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
329 views
in Technique[技术] by (71.8m points)

mouseover - Raphael JS : how to remove events?

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();
});
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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/


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...