小编给大家分享一下H5设置或返回音频/视频播放当前位置属性currentTime的示例,希望大家阅读完这篇文章之后都有所收获,下面让我们一起去探讨吧!
实例
将时间位置设置为 5 秒:
myVid=document.getElementById("video1");
myVid.currentTime=5;
定义和用法
currentTime 属性设置或返回音频/视频播放的当前位置(以秒计)。
当设置该属性时,播放会跳跃到指定的位置。
浏览器支持
所有主流浏览器都支持 currentTime 属性。
注释:Internet Explorer 8 或更早的浏览器不支持该属性。
语法
设置 currentTime 属性:
audio|video.currentTime="seconds"
返回 currentTime 属性:
audio|video.currentTime
属性值
值 | 描述 |
seconds | 指示音频/视频播放的当前位置(以秒计)。 |
技术细节
返回值 | 数字值,表示秒 |
实例
将时间位置设置为 5 秒:
<!DOCTYPE html>
<html>
<body>
<p>
<button onclick="getCurTime()" type="button">获得当前时间的位置</button>
<button onclick="setCurTime()" type="button">把时间位置设置为 5 秒</button>
</p>
<video id="video1" controls="controls">
<source src="/kf51/demo/mov_bbb.mp4" type="video/mp4">
<source src="/kf51/demo/mov_bbb.ogg" type="video/ogg">
您的浏览器不支持 video 标签。
</video>
<script>
var myVid = document.getElementById("video1");
function getCurTime() {
alert(myVid.currentTime);
}
function setCurTime() {
myVid.currentTime = 5;
}
</script>
</body>
</html>
看完了这篇文章,相信你对“H5设置或返回音频/视频播放当前位置属性currentTime的示例”有了一定的了解,如果想了解更多相关知识,欢迎关注亿速云行业资讯频道,感谢各位的阅读!
亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。