Skip to content Skip to sidebar Skip to footer

How To Properly Remove A Raphael Svg Element Referenced In An Animated Set?

I have a set of animated Raphael SVG elements. I am adding new elements and removing old ones with user initiated ajax calls. I set.push() the new elements but because the elements

Solution 1:

To remove an element from an array (which is what a Raphael set is, after all), you can use the splice function.

If you know the index of the element in the array, it's as simple as:

set.items.splice(index);

This will remove the index-th element from the array. splice returns the removed element, so if you need to remove() it or animate it off the screen, you can.

Edit: splice takes two arguments, the index in the array to remove, and how many elements you want to remove (plus any number of additional arguments which are members to add to the array, which you don't need here).

Code should read:

set.items.splice(index, 1);

Solution 2:

This may be an addition since the given answer, but set.exclude(elem) works now. For example:

varset = paper.set(),
    elem = paper.circle(50, 50, 25);
set.push(elem) // elem now in setset.exclude(elem) // what once was, forever may not be.

Post a Comment for "How To Properly Remove A Raphael Svg Element Referenced In An Animated Set?"