
- 0133技术站
- 联系QQ:88526
- QQ交流群
- 微信公众号

定义
currentTime 属性以秒为单位设置或返回当前音频/视频的播放时间;设置该属性值,可以将媒体的播放时间跳跃到指定的位置。
语法
返回 currentTime 属性值
//返回音频/视频播放的当前位置(播放时间) object.currentTime
设置currentTime 属性
//指定音频/视频播放的当前位置 object.currentTime = "秒值";
返回值:会返回一个表示秒的数字值,表示该媒体资源播放的当前位置。
浏览器支持
| HTML音频/视频 DOM属性 | |||||
currentTime | 支持 | 支持 | 支持 | 支持 | 支持 |
所有主流浏览器都支持 currentTime 属性。
注意:Internet Explorer 8 及之前的版本不支持该属性。
将时间位置设置为 5 秒:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>0133技术站(0133.cn)</title>
</head>
<body>
<br>
<video id="video" controls="controls">
<source src="http://ss.0133.cn/ueditor/php/upload/video/20190329/1553822788248551.mp4" type="video/mp4">
<source src="http://ss.0133.cn/ueditor/php/upload/video/20190329/1553822829671474.ogg" type="video/ogg">
您的浏览器不支持 HTML5 video 标签。
</video>
<br> <br>
<button onclick="getCurTime()" type="button">获得当前时间的位置</button>
<button onclick="setCurTime()" type="button">将时间位置设置为 5 秒</button>
<script>
myVid=document.getElementById("video");
function getCurTime()
{
alert(myVid.currentTime);
}
function setCurTime()
{
myVid.currentTime=5;
}
</script>
</body>
</html>点击 "运行实例" 按钮查看在线实例
推荐手册