I have a set that only contains a rectangle.
var hoverTrigger = this.paper.set();
var outline = this.paper.rect();
outline.attr({
...
hoverTrigger.push(outline)
this.sprite.push(hoverTrigger);
Upon hover, the rectangle is supposed to expand, and some links are added to it, and upon mouse off, the links disappear and the rectangle becomes small again.
hoverTrigger.hover(function () {
var link = this.paper.text();
hoverTrigger.push(link);
outline.animate({
...
}, function() {
link.remove();
outline.animate({
...
});
However, it seems like the hover function is being applied to each item in the set individually, and not the whole set, because when you go to mouse over a link, the hover off function fires and the link disappears. Sometimes the box gets hover on and hover off events in quick succession and spazzes.
Is there a way to apply a hover to a set of things, so that mousing between two things in the set doesn’t trigger hover off?
Having faced this limitation myself recently, I decided to write a small extension to Raphael called
hoverInBoundsthat resolves it.Simply, once the mouse enters the element we keep track of when it actually moves outside its bounds – executing the hover out function then, not before.
Demo: http://jsfiddle.net/amustill/Bh276/1
Place the above block of code before you create your Raphael paper object.