Animation.currentTime
Experimental: 这是一个实验中的功能
此功能某些浏览器尚在开发中,请参考浏览器兼容性表格以得到在不同浏览器中适合使用的前缀。由于该功能对应的标准文档可能被重新修订,所以在未来版本的浏览器中该功能的语法和行为可能随之改变。
Animation.currentTime 属性返回或设置动画的当前时间值(以毫秒为单位),无论动画正在运行还是已暂停。
如果动画缺少timeline
,处于非活动状态或尚未播放,则当前时间返回值为 null。
语法
var currentTime = element.currentTime; element.currentTime = someValue;
值
表示当前时间的数字(以毫秒为单位),或为 null。
例子
在Drink Me/Eat Me game中,爱丽丝的高度是可变动的,所以它可以从小到大或从大到小。在游戏开始时,通过将她的动画的 currentTime 设置为她的 keyframeEffect 的持续时间的一半让她的高度设置在两个极端之间:
aliceChange.currentTime = aliceChange.effect.timing.duration / 2;
寻求动画的 50%标记的更通用的方法:
animation.currentTime =
animation.effect.getComputedTiming().delay +
animation.effect.getComputedTiming().activeDuration / 2;
规范
Specification |
---|
Web Animations # dom-animation-currenttime |
浏览器兼容性
BCD tables only load in the browser
参见
Animation
for other methods and properties you can use to control web page animation.Animation.startTime
for the time an animation is scheduled to start.- Web Animations API