Video currentTime 属性
将时间位置设置为 5 秒:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>蜜蜂教程(mifengjc.com)</title>
</head>
<body>
<video id="myVideo" width="320" height="240" controls>
<source src="/examples/movie.mp4" type="video/mp4">
<source src="/examples/movie.ogg" type="video/ogg">
您的浏览器不支持 video 标签。
</video><br>
<button onclick="getCurTime()" type="button">获取当前时间点</button>
<button onclick="setCurTime()" type="button">设置时间位置为5秒</button>
<script>
var x = document.getElementById("myVideo");
function getCurTime() {
alert(x.currentTime);
}
function setCurTime() {
x.currentTime = 5;
}
</script>
</body>
</html>
定义和用法
currentTime 属性设置或返回视频播放的当前位置(以秒计)。
当设置该属性时,播放会跳跃到指定的位置。
浏览器支持
![]()
![]()
![]()
![]()
![]()
所有主流浏览器都支持 currentTime 属性。
注意:Internet Explorer 8 或更早的浏览器不支持该属性。
语法
返回 currentTime 属性:
videoObject.currentTime
设置 currentTime 属性:
videoObject.currentTime=seconds
属性值
| 值 | 描述 |
|---|---|
| seconds | 描述视频播放的当前位置(以秒计)。 |
技术细节
| 返回值: | 数字值,表示当前播放的时间,以秒计 |
|---|
Video 对象