JavaScript怎么实现控制视频

这篇“JavaScript怎么实现控制视频”文章的知识点大部分人都不太理解,所以小编给大家总结了以下内容,内容详细,步骤清晰,具有一定的借鉴价值,希望大家阅读完这篇文章能有所收获,下面我们一起来看看这篇“JavaScript怎么实现控制视频”文章吧。

成都创新互联公司自2013年起,先为湟中等服务建站,湟中等地企业,进行企业商务咨询服务。为湟中企业网站制作PC+手机+微官网三网同步一站式服务解决您的所有建站问题。

具体代码如下所示:




Documenttitle>
<style>
figcaption {
text-align: center;
line-height: 150px;
font-family: "Microsoft Yahei";
font-size: 24px;
}
.player {
width: 720px;
height: 360px;
margin: 10px auto;
border: 1px solid #000;
background-color: #000;
position: relative;
border-radius: 6px;
}
.player video {
width: 720px;
height: 360px;
}
.controls {
width: 700px;
height: 40px;
background-color: rgba(255,255,0,0.3);
position: absolute;
bottom: 10px;
left: 10px;
border-radius: 10px;
}
.switch {
position: absolute;
width: 22px;
height: 22px;
background-color: red;
left: 10px;
top: 9px;
border-radius: 50%;
}
.progress {
width: 432px;
height: 10px;
position: absolute;
background-color: rgba(255,255,255,0.4);
left: 40px;
top: 15px;
border-radius: 4px;
overflow: hidden;
}
.curr-progress {
width: 0%;
height: 100%;
background-color: #fff;
}
.time {
width: 120px;
height: 20px;
text-align: center;
line-height: 20px;
font-size: 12px;
color: #fff;
position: absolute;
left: 510px;
top: 10px;
}
.extend {
position: absolute;
width: 20px;
height: 20px;
background-color: red;
right: 10px;
top: 10px;
}
style>
head>
<body>
<figure>  
<figcaption>视频案例figcaption>
<div class="player">
<video src="11.mp4">video>
<div class="controls">
<a href="#" class="switch">a>
<div class="progress">
<div class="curr-progress">div>
div>
<div class="time">
<span class="curr-time">00:00:00span>/
<span class="total-time">00:00:00span>
div>
<a href="#" class="extend">a>
div>
div>
figure>
<script>
var video = document.querySelector('video');
var playBtn = document.querySelector('.switch');
var currProgress = document.querySelector('.curr-progress');
var currTime = document.querySelector('.curr-time');
var totalTime = document.querySelector('.total-time');
var extend = document.querySelector('.extend');
var tTime = 0;
playBtn.onclick = function() {
if(video.paused){  // 如果视频是暂停的
video.play();    //play()播放  load()重新加载  pause()暂停
}else{
video.pause();
}
}
//当视频能播放(已经通过网络加载完成)时
video.oncanplay = function() {
tTime = video.duration;  //获取视频总时长(单位秒)
var tTimeStr = getTimeStr(tTime);
totalTime.innerHTML = tTimeStr;
}
//当视频当前播放时间更新的时候
video.ontimeupdate = function() {
var cTime = video.currentTime;  //获取当前播放时间 
var cTimeStr = getTimeStr(cTime);
console.log(cTimeStr);
currTime.innerHTML = cTimeStr;
currProgress.style.width = cTime/tTime*100+"%";
}
extend.onclick = function() {
video.webkitRequestFullScreen();  //视频全屏
}
//将以秒为单位的时间变成“00:00:00”格式的字符串
function getTimeStr(time) {
var h = Math.floor(time/3600);
var m = Math.floor(time%3600/60);
var s = Math.floor(time%60);
h = h>=10?h:"0"+h;
m = m>=10?m:"0"+m;
s = s>=10?s:"0"+s;
return h+":"+m+":"+s;
}
script>
body>
html></pre><p>以上就是关于“JavaScript怎么实现控制视频”这篇文章的内容,相信大家都有了一定的了解,希望小编分享的内容对大家有帮助,若想了解更多相关的知识内容,请关注创新互联行业资讯频道。</p>            
            
                            <br>
                网站名称:JavaScript怎么实现控制视频                <br>
                链接URL:<a href="http://myzitong.com/article/gddseh.html">http://myzitong.com/article/gddseh.html</a>
            </div>
        </div>
        <div class="contentr fr">
            <h3>其他资讯</h3>
            <ul>
                <li>
                        <a href="/article/diohddd.html">android让按钮居中 android按钮布局</a>
                    </li><li>
                        <a href="/article/diohogh.html">输入框不触发jquery js设置输入框不可编辑</a>
                    </li><li>
                        <a href="/article/diohddo.html">mysql怎么表格数据 mysql数据库表格</a>
                    </li><li>
                        <a href="/article/diohohe.html">mysql两个表怎么创建 mysql两个表怎么联系</a>
                    </li><li>
                        <a href="/article/diohojd.html">指针c语言函数 c语言中指针的指针</a>
                    </li>            </ul>
        </div>
    </div>
</div>
<!--底部-->
<footer>
    <div class="foot">
        <div class="container">
            <h1>梓潼大橙子建站您身边的网站制作服务商</h1>
            <div class="foot1">
                <ul>
                    <li>
                        <dl><i class="iconfont"></i><b>地址ADDRESS</b></dl>
                        <p>四川-成都青羊区太升南路288号<br>
                            锦天国际A座10楼
                        </p>
                    </li>
                    <li>
                        <dl><i class="iconfont"></i><b>电话/TEL</b></dl>
                        <p><a href="tel:02886922220" target="_blank">028 86922220</a> (工作日)<br>
                            <a href="tel:18980820575" target="_blank">1898082 0575</a> ( 7x24 )
                        </p>
                    </li>
                    <li>
                        <dl><i class="iconfont"></i><b>QQ咨询</b></dl>
                        <p> 244261566 (售前)<br>
                            631063699 (售后)
                        </p>
                    </li>
                    <li>
                        <dl><i class="iconfont"></i><b>邮箱/E: mail</b></dl>
                        <p> service@cdcxhl.com (业务)<br>
                            hr@cdcxhl.com (求职)
                        </p>
                    </li>
                </ul>
            </div>
            <div class="link">
                友情链接:
                <a href="https://www.cdxwcx.com/city/leshan/" title="乐山做网站" target="_blank">乐山做网站</a>   <a href="https://www.cdxwcx.com/wangzhan/mbshangcheng.html" title="B2C电商系统" target="_blank">B2C电商系统</a>   <a href="http://www.xhgfhy.com/
" title="郫县封阳台" target="_blank">郫县封阳台</a>   <a href="http://chengdu.cdcxhl.cn/" title="成都网站设计" target="_blank">成都网站设计</a>   <a href="https://www.cdcxhl.com/h5.html" title="成都h5网站建设" target="_blank">成都h5网站建设</a>   <a href="http://www.cdszcl.cn/" title="顺泽窗帘" target="_blank">顺泽窗帘</a>   <a href="https://www.cdcxhl.com/idc/gysx.html" title="贵阳托管服务器" target="_blank">贵阳托管服务器</a>   <a href="http://www.cxhljz.com/" title="成都网站建设" target="_blank">成都网站建设</a>   <a href="https://www.cdxwcx.com/wangzhan/shop.html" title="网上商城管理系统" target="_blank">网上商城管理系统</a>   <a href="http://www.028jzp.com/" title="成都酒店服定制" target="_blank">成都酒店服定制</a>               </div>
        </div>
    </div>
    <div class="copy container">
        Copyright