如何正确删除动画集引用的拉斐尔SVG元素? [英] How to properly remove a Raphael SVG element referenced in an animated set?
问题描述
我有一组动画拉斐尔SVG元素。我加入新的元素和去除旧有用户发起Ajax调用。我set.push()的新元素,而是因为我需要删除的元素往往不是在集中的最后一个要素,我使用element.remove()而不是set.pop()。这使得在集,当我打电话set.animate(),使动画回调方法不能被称为一个删除的元素。也许这就是拉斐尔1.5.2中的错误。
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 I need to remove are frequently not the last elements in the set, I am using element.remove() instead of set.pop(). This leaves a removed element in the set, which when I call set.animate(), causes the animation callback method to NOT be called. Perhaps this is a bug in Raphael 1.5.2.
的jsfiddle例如: http://jsfiddle.net/G7fAQ/
jsFiddle example: http://jsfiddle.net/G7fAQ/
有没有更好的方式来删除在动画集引用的元素?或者,我只是有手动管理set.items阵列,set.length变量,并设置元素时我所说的element.remove()?
Is there a better way to remove elements that are referenced in an animated set? Or do I simply have to manually manage the set.items array, set.length variable, and set elements when I call the element.remove()?
即。 http://jsfiddle.net/G7fAQ/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.
编辑:拼接
有两个参数,该指数在阵列中去除,你想有多少个元素删除(外加任意数量的这是成员的其他参数添加到数组,你不需要在这里)。
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应改为:
set.items.splice(index, 1);
这篇关于如何正确删除动画集引用的拉斐尔SVG元素?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!