删除拉斐尔元素有时会导致它崩溃?
我有一个 Raphael javascript 程序,其中有几个(几十个,几百个,等等)圆圈写入页面,如下所示:
evo_sprite = paper.circle(evo.x, evo.y, this.evo_size);
每个圆圈都有有限的时间,我希望它显示,之后我希望它被销毁,这样它就不会不要放慢速度。
当我这样做时:
evo_sprite.hide();
我没有问题,但我知道精灵仍然存在,因此仍然占用内存。
所以我尝试了:
evo_sprite.remove();
并得到了相同的结果(圆圈不再显示)。
唯一的问题是,在一段时间后(似乎是随机的),我的程序冻结并收到错误消息:
a1.paper 未定义 [打破这个错误] Raphael=(function(){var a=/[, ]+/,aO=/...eturn d;};an.el=ax[aY];return an;})() ;
这对任何人都有意义吗?我是否错误地调用了删除?我如何通过在圆上调用删除来导致 Raphael 的代码(在 min 文件的第 7 行)中断?
I have a Raphael javascript program, where I have several (dozens, hundreds, whatever) circles written to the page, like so:
evo_sprite = paper.circle(evo.x, evo.y, this.evo_size);
Each circle has a limited amount of time I want it displayed, after which I want it destroyed so it doesn't slow stuff down.
When I do:
evo_sprite.hide();
I have no problems, but I know the sprite is still there, and thus still taking up memory.
So I tried:
evo_sprite.remove();
And got what APPEARED to be the same result (the circle is no longer displayed).
The only problem is that after some amount of time(seems random), my program freezes and I get the error message:
a1.paper is undefined
[Break On This Error] Raphael=(function(){var a=/[, ]+/,aO=/...eturn d;};an.el=ax[aY];return an;})();
Does this make sense to anybody? Am I calling remove incorrectly? How am I causing Raphael's code (on line 7 of the min file) to break just by calling remove on a circle?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果不查看您的代码,很难知道,但看起来它是未找到的 Raphael 画布(我认为这就是 a1.paper )。
您是否在 document.onload(或使用 jQuery 的 $(document).ready)上实例化 Raphael 画布?确保代码中不存在任何导致函数尝试在 a1.paper 范围之外运行的闭包。
然后回到基础知识 - 首先尝试几个圆圈,然后是 50 个圆圈,然后是 100 个圆圈。然后在不同的浏览器中尝试,看看它是否在所有浏览器中停止工作。 SVG 是浏览器密集型的,因此创建数千个圆圈可能会使某些浏览器崩溃。
It's difficult to know without seeing your code, but it looks like it is the Raphael canvas that isn't being found (I presume that's what a1.paper is).
Are you instantiating your Raphael canvas on document.onload (or $(document).ready with jQuery)? Make sure there aren't any closures in your code that make functions trying to operate outside the scope of a1.paper.
Then go right back to basics - try it with just a few circles to begin with, then 50, then 100. Then try it in different browsers and see whether it stops working in all of them. SVG is quite browser intensive, so creating thousands of circles might make some browsers break.