189 8069 5689

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>
            转载来源:<a href="http://zwzwh.cn/article/gddseh.html">http://zwzwh.cn/article/gddseh.html</a>
        </div>
    </div>
    <div class="other">
        <h3>其他资讯</h3>
        <ul>
            <li>
                    <a href="/article/hped.html">兴和是哪里(明朝兴和堡)</a>
                </li><li>
                    <a href="/article/dccisi.html">nginx虚拟机配置和location的使用方法-创新互联</a>
                </li><li>
                    <a href="/article/gdcogd.html">nodejsAssert中equal(),strictEqual(),deepEqual(),strictDeepEqual()比较</a>
                </li><li>
                    <a href="/article/hcppsi.html">php处理数据帧,php获取视频第一帧</a>
                </li><li>
                    <a href="/article/doieeph.html">mysql过期了怎么解决 mysql删除过期数据</a>
                </li><li>
                    <a href="/article/dseiiej.html">android混音,android混音增益</a>
                </li><li>
                    <a href="/article/dgjhigd.html">android字符串替换 android string 换行</a>
                </li><li>
                    <a href="/article/coigdhe.html">IIS指令:Get-WebRequest-获取Web请求</a>
                </li><li>
                    <a href="/article/cddopeo.html">中国移动全球通28元套餐介绍?(日本动态拨号云服务器有哪些应用场景)</a>
                </li><li>
                    <a href="/article/cdisdss.html">选择合适的VPS技巧?</a>
                </li>        </ul>
    </div>
</div>
<footer>
    <div class="foot container">
        <div class="footl fl">
            <h3>联系我们</h3>
            <dl>
                您好HELLO!<br>
                感谢您来到成都网站建设公司,若您有合作意向,请您为我们留言或使用以下方式联系我们,

                我们将尽快给你回复,并为您提供真诚的设计服务,谢谢。
            </dl>
            <ul>
                <li>电话:028- <span>86922220 18980695689</span></li>
                <li>商务合作邮箱:631063699@qq.com</li>
                <li>合作QQ: 532337155</li>
                <li>成都网站设计地址:成都市青羊区锣锅巷31号五金站写字楼6楼</li>
            </ul>
        </div>
        <div class="footr fr">
            <h3>乐尚佳建站工作室</h3>
            <dl>
                成都乐尚佳网站建设公司拥有多年以上互联网从业经验的精英团队,始终保持务实的风格,以"帮助客户成功"为已任,专注于提供对客户有价值的服务。

                我们已为众企业及上市公司提供专业的网站建设服务。我们不只是一家网站建设的网络公司;我们对营销、技术、管理都有自己独特见解,乐尚佳建站采取“创意+综合+营销”一体化的方式为您提供更专业的服务!
            </dl>
            <h3>乐尚佳观点</h3>
            <dl>
                相对传统的成都网站建设公司而言,乐尚佳鼎是互联网中的网站品牌策划精英,我们精于企业品牌与互联网相结合的整体战略服务。<br>
                我们始终认为,网站必须注入企业基因,真正使网站成为企业vi的一部分,让整个网站品牌策划体系变的深入而持久。
            </dl>
        </div>
    </div>
    <div class="link">
        <div class="container"> <span> 友情链接:</span>
            <a href="http://www.chaizegs.com/" title="成都发电机维修公司" target="_blank">成都发电机维修公司</a>   <a href="http://www.fzwuji.cn/" title="成都门头广告" target="_blank">成都门头广告</a>   <a href="http://www.minganxf.com/" title="郫都区消防器材" target="_blank">郫都区消防器材</a>   <a href="http://www.finscp.com/" title="大邑网站制作" target="_blank">大邑网站制作</a>   <a href="http://www.maomibieshu.cn/" title="宠物用品" target="_blank">宠物用品</a>   <a href="http://www.jljierui.cn/" title="龙泉网站建设" target="_blank">龙泉网站建设</a>   <a href="http://www.adchuangyi.com/" title="成都广告设计" target="_blank">成都广告设计</a>   <a href="https://www.cdxwcx.com/city/leshan/" title="乐山做网站" target="_blank">乐山做网站</a>   <a href="http://www.qcngdk.com/" title="凉山网站制作" target="_blank">凉山网站制作</a>   <a href="http://www.ncyilong.com/" title="仪陇网站建设" target="_blank">仪陇网站建设</a>           </div>
    </div>
      <div class="copy">