Skip to content

chore(zh-CN): translation of Web/API/Window/requestAnimationFrame#34912

Open
Totoro-jam wants to merge 1 commit intomdn:mainfrom
Totoro-jam:update-requestanimationframe-zh-cn
Open

chore(zh-CN): translation of Web/API/Window/requestAnimationFrame#34912
Totoro-jam wants to merge 1 commit intomdn:mainfrom
Totoro-jam:update-requestanimationframe-zh-cn

Conversation

@Totoro-jam
Copy link
Copy Markdown
Contributor

Description

同步更新 Window.requestAnimationFrame 的中文翻译,包含以下内容:

  • 添加 short-title 元数据
  • 更新 l10n.sourceCommit 为最新提交
  • 更新警告框内容,修正溢出时间(500天→800天)
  • 更新示例代码,使用更简洁的 Math.min() 实现
  • 新增三种时间零点设置方法的详细示例说明
  • 更新参见部分,添加相关链接

Motivation

英文原文的示例代码和说明有较大更新,包括:

  • 更精确的动画时间计算方法
  • 多种时间零点设置的对比说明
  • document.timeline.currentTime 同步的新方法

这些内容对开发者正确使用 requestAnimationFrame 至关重要。

Additional details

Related issues and pull requests

@Totoro-jam Totoro-jam requested a review from a team as a code owner April 2, 2026 08:21
@Totoro-jam Totoro-jam requested review from jasonren0403 and removed request for a team April 2, 2026 08:21
@github-actions github-actions bot added the l10n-zh Issues related to Chinese content. label Apr 2, 2026
@Totoro-jam Totoro-jam force-pushed the update-requestanimationframe-zh-cn branch 2 times, most recently from 7ac72c7 to a144e55 Compare April 2, 2026 09:04
@Totoro-jam Totoro-jam force-pushed the update-requestanimationframe-zh-cn branch from a144e55 to 622267e Compare April 3, 2026 06:04
Copy link
Copy Markdown
Contributor

@PassionPenguin PassionPenguin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

感谢贡献,但是请 1. 不要滥用人工智能或其他机器学习翻译工具 2. 检查你的译文是否符合 https://github.com/mdn/translated-content/blob/main/docs/zh-cn/translation-guide.md

其他 PR 同

slug: Web/API/Window/requestAnimationFrame
l10n:
sourceCommit: f9f48866f02963e752717310b76a70d5bdaf554c
sourceCommit: 14964f7b946f7e7f19c1a0a2f71e4e8db60ecd4a
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

?何意味,目标文件从来没有这个hash

Copy link
Copy Markdown
Contributor

@PassionPenguin PassionPenguin Apr 4, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

### 返回值

请求 ID 是一个 `long` 类型整数值,是在回调列表里的唯一标识符。这是一个非零值,但你不能对该值做任何其他假设。你可以将此值传递给 {{domxref("window.cancelAnimationFrame()")}} 函数以取消该刷新回调请求。
一个 `unsigned long` 整数值,即请求 ID,是在回调列表里的唯一标识符。这是一个非零值,但你不能对该值做任何其他假设。你可以将此值传递给 {{domxref("window.cancelAnimationFrame()")}} 函数以取消该刷新回调请求。
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

**`window.requestAnimationFrame()`** 方法会告诉浏览器你希望执行一个动画。它要求浏览器在下一次重绘之前,调用用户提供的回调函数。

对回调函数的调用频率通常与显示器的刷新率相匹配。虽然 75hz、120hz 和 144hz 也被广泛使用,但是最常见的刷新率还是 60hz(每秒 60 个周期/帧)。为了提高性能和电池寿命,大多数浏览器都会暂停在后台选项卡或者隐藏的 {{ HTMLElement("iframe") }} 中运行的 `requestAnimationFrame()`。
对回调函数的调用频率通常与显示器的刷新率相匹配。最常见的刷新率是 60hz(每秒 60 个周期/帧),不过 75hz、120hz 和 144hz 也被广泛使用。为了提高性能和电池寿命,大多数浏览器都会暂停在后台选项卡或者隐藏的 {{ HTMLElement("iframe") }} 中运行的 `requestAnimationFrame()`。
Copy link
Copy Markdown
Contributor

@PassionPenguin PassionPenguin Apr 3, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

何区别?


> [!WARNING]
> 请求 ID 通常实现为每个窗口的递增计数器。因此,即使它从 1 开始计数,也可能会溢出并最终达到 0。虽然这不太可能对短期应用程序造成问题,但你应该避免使用 `0` 作为无效请求标识符 ID 的哨兵值,而应该使用无法达到的值,如 `null`。规范没有指定溢出行为,因此浏览器具有不同的行为。溢出时,该值要么回绕到 0,要么变为负值,要么抛出错误。除非溢出会抛出异常,否则请求 ID 也不是真正唯一的,因为对于可能无限多的回调函数,只有有限多个 32 位整数。但请注意,在 60Hz 渲染频率下,每帧调用 100 次 `requestAnimationFrame()`,大约需要 500 天才会出现此问题。
> 请求 ID 通常实现为每个窗口的递增计数器。因此,即使它从 1 开始计数,也可能会溢出并最终达到 0。虽然这不太可能对短期应用程序造成问题,但你应该避免使用 `0` 作为无效请求标识符 ID 的哨兵值,而应该使用无法达到的值,如 `null`。
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

目标语言为中文的译文种,请不要把同属一行的段落拆开

以下三个示例说明了设置时间零点的不同方法,时间零点是计算每帧动画进度的基准。如果你想与外部时钟同步,例如 {{domxref("BaseAudioContext.currentTime")}},可用的最高精度是单帧的持续时间(60Hz 时为 16.67ms)。回调的时间戳参数表示上一帧的结束时间,因此新计算的值最快会在下一帧中呈现

此示例会等待第一个回调函数执行时设置 `zero`。如果你的动画在开始时跳转到新值,则必须采用这种结构。如果你无需与任意外部同步(例如音频),则建议使用此方法,因为某些浏览器在首次调用 `requestAnimationFrame()` 和首次调用回调函数之间会有多帧延迟。
此示例等待第一个回调执行时设置 `zero`。如果你的动画在开始时跳转到新值,则必须采用这种结构。如果你不需要与任何外部内容(如音频)同步,则建议使用此方法,因为某些浏览器在首次调用 `requestAnimationFrame()` 和首次调用回调函数之间会有多帧延迟。
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

此示例等待第一个回调执行时设置 zero

请不要滥用人工智能完成翻译,译文请稍微检查一下倒也不要太离谱吧

Copy link
Copy Markdown
Contributor Author

@Totoro-jam Totoro-jam Apr 3, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

好的👌,抱歉,我会全部在review一次,非常感谢你的认真审阅和宝贵的时间,有一些确实是我尝试用过往的closed的中文pr训练的skill 让agent处理的,认真接受你的指正。我会全部审查一次。

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

好的👌,抱歉,我会全部在review一次,非常感谢你的认真审阅和宝贵的时间,有一些确实是我尝试用过往的closed的中文pr训练的skill 让agent处理的,认真接受你的指正。我会全部审查一次。

yeap,非常感谢

机器学习支持的翻译技术的语料有不少是别的学科,别的语言的,同时也会有不准确的数据,导致翻译出来的译文会在可读性角度、流畅角度,以及最重要的部分术语与目标译文有偏差,翻译完后可以粗略过一两次哒

- [用 JavaScript 做动画:从 setInterval 到 requestAnimationFrame](https://hacks.mozilla.org/2011/08/animating-with-javascript-from-setinterval-to-requestanimationframe/)——博文
- [TestUFO:测试你的 web 浏览器 requestAnimationFrame() 的时间偏差](https://www.testufo.com/#test=animation-time-graph)
- [TestUFO:测试你的 web 浏览器 requestAnimationFrame() 的时间偏差](https://testufo.com/#test=animation-time-graph)
- [Firefox 切换到 uint32_t 作为 requestAnimationFrame 请求 ID](https://phabricator.services.mozilla.com/rMOZILLACENTRAL149722297f033d5c3ad126d0c72edcb1cb96d72e)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这是中文吗

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 7, 2026

Preview URLs (1 page)

External URLs (2)

URL: /zh-CN/docs/Web/API/Window/requestAnimationFrame
Title: Window:requestAnimationFrame() 方法

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

l10n-zh Issues related to Chinese content.

Projects

Status: In progress - PRs

Development

Successfully merging this pull request may close these issues.

2 participants