网页上多个html5 canvas元素的计时实践

发布于 2024-12-06 07:49:55 字数 383 浏览 0 评论 0原文

我发现了一些关于使用请求动画帧对 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

ぃ双果 2024-12-13 07:49:55

我假设您将单独开发每个动画,并且这些动画彼此不相关。在这种情况下,您根本不需要同步...如果您在一个循环中同步它们,您将遇到以下问题...

  • 如果一个画布中的动画很慢,则其他画布中的动画将不得不不必要地等待。 ..
  • requestAnimationFrame 帮助您创建智能循环,即如果您的画布处于隐藏状态或您的选项卡未处于活动状态,则画布不会发生回调。如果进行同步,您将无法完全优化。
    • 在一个循环中管理所有动画比在单个循环中管理要复杂得多。
  • 在调试时,您可能会遇到页面中其他动画引起的问题...

因此,如果您的动画不相关,我强烈建议不要将动画与一个循环同步。希望这能回答您的问题。

以下链接将帮助您了解有关 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...

  • If animation in one canvas is slow, animation in other canvas will have to unnecessarily wait...
  • requestAnimationFrame help you create intelligent loop, ie if your canvas in hidden or your tab is not active, callback will not occur for canvas. In case of syncing, you will not be able to optimize fully.
    • It will be more complex to manage all the animation in one loop rather then individual loop.
  • While debugging, you may come across problems caused by other animations in the page...

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...

骄傲 2024-12-13 07:49:55

这完全取决于你。您是否希望这些元素彼此同步运行?还是没关系?

如果无关紧要或者您需要同步它们,请使用一个计时器将它们全部保留在一个循环中。它在每个浏览器上可能会更快,并且更容易调试、维护和理解代码。

如果它们不应该同步,那么您当然必须有两个计时器!另外,如果您觉得将来您可能希望不同的部分以明显不同或变化的速度运行,那么您可能需要考虑两个计时器。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文