简体   繁体   English

对1400个Raphael.js对象的不透明度进行动画处理会损害动画性能

[英]Animating opacity of 1400 Raphael.js objects hurts animating performance

First off, thank you for any help. 首先,谢谢您的帮助。 :) :)

JSFiddle code . JSFiddle代码

JSFiddle full screen JSFiddle全屏

As you can see by the fiddle link above I am animating 1400 objects trying to create a 'twinkling effect'. 如您在上方的小提琴链接中所看到的,我正在为1400个对象设置动画,以尝试创建“闪烁效果”。 As the user moves the mouse faster more hexagon shapes pop into full opacity and have varying fade out rates. 随着用户更快地移动鼠标,更多的六边形会弹出完全不透明的状态,并且淡出率会有所不同。 The version in the fiddle fills the space with enough color but feels jerky and clumpy. 小提琴中的版本用足够的颜色填充了空间,但感觉生涩而结块。 If I lessen the fade_time variable amounts it is smoother but does not have enough hexagons with full opacity. 如果我减少fade_time变量的数量,则它会更平滑,但没有足够的六边形且完全不透明。 The end goal is to spell words with the hexagons. 最终目标是用六边形拼写单词。

The performance in Chrome is best, less so in FireFox and IE. Chrome的性能最好,而FireFox和IE则不然。 I tested (using Raphael's element.touchmove) in mobile safari on an iPad and it was even worse. 我在iPad上的移动浏览器中测试(使用Raphael的element.touchmove),甚至更糟。

I'm looking for any advice on what pieces of the code could be done differently for performance gains. 我正在寻找有关可以以不同方式完成代码部分以提高性能的任何建议。

I saw this answer somebody else gave that was supposed to help with performance, but I'm trying to base the amount of animating hexagons on cursor movement and I'm not sure I could do that with a timer. 我看到了其他人给出的答案 ,应该可以改善性能,但是我正在尝试根据光标移动量设置六边形的动画效果,我不确定是否可以使用计时器来实现。

This answer mentioned using canvas: 使用画布提到了以下答案

A good alternative would be using Canvas to draw the elements. 一个很好的选择是使用“画布”绘制元素。 From my experiments it will be faster than SVG at drawing this many although if you are using some animations, they will be harder to implement than with the RaphaelJS library. 根据我的实验,绘制这么多动画的速度将比SVG快,尽管如果您使用某些动画,则与RaphaelJS库相比,实现起来会更加困难。

Does that seem like a better route to people, even with the animations the code is using? 即使使用代码使用的动画,这似乎也是通向人们的更好的途径吗?

This is my first use of Raphael.js. 这是我第一次使用Raphael.js。 I'm not very experienced in JS in general, so any help is wunderbar! 一般而言,我对JS的经验不是很丰富,所以任何帮助都是不可思议的!

Edit: Edit: Also, seeing this answer about .resize being called more times than the questioner might have thought got me wondering if the .mousemove function may be called more times (more than I would need) than I would expect. 编辑:编辑:另外,看到这个答案约.resize被称为比提问者可能认为更多的时间让我想知道如果.mousemove函数可以被称为多的时间(超过我需要),比我期望的那样。

I think it chokes on "overlapped" animations, ie for example: 我认为它在“重叠”动画上令人窒息,例如:

  1. hexagon number #6 starts its fade 6号六角形开始褪色
  2. at a half of its fade, another fade is started 在其褪色的一半处开始另一种褪色

I added a stop() instruction to avoid unexpected results. 我添加了stop()指令以避免出现意外结果。

Besides, the for() cycle doesn't check if another animation is in progress, nor if some hex has been randomly selected twice or more inside the cycle. 此外,for()循环不会检查是否正在进行其他动画,也不会检查循环内是否已两次或多次随机选择一些十六进制。 As a workaround for this, I added a vector to cache the indexes of the hexagons being animated, although it does not seem to be of great help. 作为解决方法,我添加了一个向量来缓存正在动画的六边形的索引,尽管它似乎并没有太大帮助。

To see how many (useless) animations it saved, uncomment the last console.log() . 要查看它保存了多少个(无用的)动画,请取消注释最后一个console.log()

Besides, your getRandomInt() function generated some undefined index errors (since your array indexes go from 0 to 1399 and it returned integers between 0 and 1400... I changed it. 此外,您的getRandomInt()函数生成了一些未定义的索引错误(因为数组索引从0到1399,并且它返回0到1400之间的整数...我更改了它。

See my add-ons here: http://jsfiddle.net/rz4yY/46/ 在这里查看我的附加组件: http : //jsfiddle.net/rz4yY/46/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM