网页上多个html5 canvas元素的计时实践
我发现了一些关于使用请求动画帧对 html5 canvas 元素进行动画处理的文章。 http://paulirish.com/2011/requestanimationframe-for-smart-animating/
如果我有多个元素,我应该为每个元素单独设置一个计时系统(一个单独的脚本),还是应该将它们全部放在一个循环中?
这是针对杂志概念的,其中您可能每个“页面”都有不同的动画(一个是一系列线条,另一个是波浪,也许另一个在您阅读文本时在您眼前分解图像)
任何帮助总是值得赞赏。
I have found some articles on using request animation frames for animating html5 canvas elements. http://paulirish.com/2011/requestanimationframe-for-smart-animating/
If I were to have multiple elements, should I have a timing system for each of them individually (a separate script) or should I have them all within a single loop?
This is for a magazine concept, wherein you may have each 'page' with a different animation (one a series of lines, another a wave, perhaps another that disintegrates an image before your eyes as you read the text)
any help is always appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我假设您将单独开发每个动画,并且这些动画彼此不相关。在这种情况下,您根本不需要同步...如果您在一个循环中同步它们,您将遇到以下问题...
因此,如果您的动画不相关,我强烈建议不要将动画与一个循环同步。希望这能回答您的问题。
以下链接将帮助您了解有关 Html5 Canvas 的更多信息...
I assume that you will develop each animations separately, and further these animations are not related with each other. In such case you not at all need for synchronization... If you go for sync them up in one loop, you will have following problems...
So if your animations are not related, I highly recommend not to sync the animations with one loop. Hope this answers your questions.
Following link will help you learn more about Html5 Canvas...
这完全取决于你。您是否希望这些元素彼此同步运行?还是没关系?
如果无关紧要或者您需要同步它们,请使用一个计时器将它们全部保留在一个循环中。它在每个浏览器上可能会更快,并且更容易调试、维护和理解代码。
如果它们不应该同步,那么您当然必须有两个计时器!另外,如果您觉得将来您可能希望不同的部分以明显不同或变化的速度运行,那么您可能需要考虑两个计时器。
That's entirely up to you. Do you want the elements to run in sync with each other or not? Or does it not matter?
If its doesn't matter or if you need them synced, keep them all in one loop with one timer. It's probably faster on every browser and it will be easier to debug, maintain, and understand the code.
If they shouldn't be synced up then of course you must have two timers! Also, if you feel in the future you might want different parts to run at distinctly different or changing speeds, then you might want to consider two timers.