点击图片让video视频显示并自动播放/循环播放

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/JINQINGS/article/details/54695030

HTML:
<video width="100%" height="300" id="video" style="object-fit:fill;">
    <source src="https://video.mp4" type="video/mp4">
</video>
<img src="../images/video.png"  id="video2">
JS:
<script type="text/javascript">
var video2=document.getElementById("video2");
var myVideo=document.getElementById("video");
video2.onclick = function(){
    video2.style.display = "none";
    var vList = ['https://video.mp4'];
    var vLen = vList.length;
    var curr = 0;
    myVideo.addEventListener('ended', function () {    //监听视频是否已经结束事件
        playVid();
    });
    function playVid() {
        myVideo.src = vList[curr];
        myVideo.load();
        myVideo.play();
        curr++;
        if (curr >= vLen) {
            curr = 0; //重新循环播放
        }
    }
    $(function () {
        playVid();
    })
}
</script> 

展开阅读全文

没有更多推荐了,返回首页