Animation.updatePlaybackRate() - Web APIs 编辑
Experimental
This is an experimental technology
Check the Browser compatibility table carefully before using this in production.
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 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 playbackRate
is not immediately updated. It will be updated once the animation's ready
promise is resolved.
Syntax
Animation.updatePlaybackRate(2);
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.
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
Specification | Status | Comment |
---|---|---|
Web Animations The definition of 'updatePlaybackRate()' in that specification. | Working Draft |
Browser compatibility
BCD tables only load in the browser
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论