大网数据广告活动
Web 标准与前端开发

Animation: updatePlaybackRate() method

· 52CE 我爱测

The **`updatePlaybackRate()`** method of the Web Animations API's Animation Interface sets the speed of an animation after first synchronizing its playback position.

Web Animations

The updatePlaybackRate() method of the Web Animations API's Animation Interface sets the speed of an animation after first synchronizing its playback position.

In some cases, an animation may run on a separate thread or process and will continue updating even while long-running JavaScript delays the main thread. In such a case, setting the Animation.playbackRate on the animation directly may cause the animation's playback position to jump since its playback position on the main thread may have drifted from the playback position where it is currently running.

updatePlaybackRate() is an asynchronous method that sets the speed of an animation after synchronizing with its current playback position, ensuring that the resulting change in speed does not produce a sharp jump. After calling updatePlaybackRate() the animation's Animation.playbackRate is not immediately updated. It will be updated once the animation's Animation.ready promise is resolved.

Syntax

updatePlaybackRate(playbackRate)

Parameters

  • playbackRate
    • : The new speed to set. This may be a positive number (to speed up or slow down the animation), a negative number (to make it play backwards), or zero (to effectively pause the animation).

Return value

None (undefined).

Examples

A speed selector component would benefit from smooth updating of updatePlaybackRate(), as demonstrated below:

speedSelector.addEventListener("input", (evt) => {
  cartoon.updatePlaybackRate(parseFloat(evt.target.value));
  cartoon.ready.then(() => {
    console.log(`Playback rate set to ${cartoon.playbackRate}`);
  });
});

Specifications

Browser compatibility

See also

  • Web Animations API
  • Animation.playbackRate — read back the current playback rate or set it in a synchronous manner.
  • Animation.reverse() — invert the playback rate and restart playback if necessary.
  • Animation — contains other methods and properties you can use to control web page animation.

来源:MDN Web Docs / Mozilla 贡献者 · 作者与贡献记录 · CC BY-SA 2.5。离线整理了版式、链接和媒体显示。

资料来源与适用范围

资料来源
MDN Web Docs / Mozilla 贡献者
适用范围
请按文中版本与环境说明核对
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 2.5

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。