JavaScript如何实现控制视频
这篇文章将为大家详细讲解有关JavaScript如何实现控制视频,小编觉得挺实用的,因此分享给大家做个参考,希望大家阅读完这篇文章后可以有所收获。
网站设计制作过程拒绝使用模板建站;使用PHP+MYSQL原生开发可交付网站源代码;符合网站优化排名的后台管理系统;网站设计制作、成都网站建设收费合理;免费进行网站备案等企业网站建设一条龙服务.我们是一家持续稳定运营了十载的创新互联网站建设公司。
具体代码如下所示:
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://ybzwz.com/article/jjoide.html">http://ybzwz.com/article/jjoide.html</a> </div> </div> <div class="contentr fr"> <h3>其他资讯</h3> <ul> <li> <a href="/article/doigsdh.html">怎么把mysql授权删去 mysql移除用户权限</a> </li><li> <a href="/article/doigsdp.html">JAVA退出悬浮代码 java退出函数</a> </li><li> <a href="/article/doigsos.html">gis虚拟现实技术的应用 虚拟现实在gis可视化中的意义</a> </li><li> <a href="/article/doigcps.html">如何查看zblog订单 zblogguan网</a> </li><li> <a href="/article/doigcpi.html">帝国cms留言板不存在 帝国cms信息反馈</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="http://www.kmruizhi.cn/" title="kmruizhi.cn" target="_blank">kmruizhi.cn</a> <a href="http://www.cdxwcx.cn/tuoguan/mianyang.html" title="绵阳机房托管" target="_blank">绵阳机房托管</a> <a href="http://www.scbaiwuyu.cn/" title="四川白乌鱼" target="_blank">四川白乌鱼</a> <a href="http://www.cdxwcx.cn/tuoguan/leshan.html" title="乐山电信机房" target="_blank">乐山电信机房</a> <a href="http://www.cdkjz.cn/fangan/response/" title="响应式网站建设方案" target="_blank">响应式网站建设方案</a> <a href="https://www.xwcx.net/tuoguan.html" title="电信机房托管服务器" target="_blank">电信机房托管服务器</a> <a href="http://www.ynruijie.com/" title="成都公司注册" target="_blank">成都公司注册</a> <a href="http://www.bzwzjz.com/" title="专业网站建设" target="_blank">专业网站建设</a> <a href="http://m.cdcxhl.com/liucheng.html" title="成都网站建设流程" target="_blank">成都网站建设流程</a> <a href="http://www.gylewan.com/" title="不锈钢招牌" target="_blank">不锈钢招牌</a> </div> </div> </div> <div class="copy container"> Copyright © 2017-2022 All Rights Reserved. 青羊区小谭信息技术咨询服务工作室 版权所有 <a href="http://www.beian.miit.gov.cn/" target="_blank" rel="nofollow">蜀ICP备2021004003号-22</a> [原创设计,独立版权。未经许可.不得拷贝或镜像]<br> <a href="http://www.kswsj.cn/" target="_blank">网站营销推广</a> | <a href="https://www.cdcxhl.com/pinpai.html" target="_blank">品牌网站设计</a> | <a href="http://www.cdweb.net/" target="_blank">自适应网站建设</a> | <a href="http://cdkjz.cn/wangzhan/pinpai/" target="_blank">品牌网站建设</a> | <a href="http://chengdu.cdxwcx.cn/" target="_blank">成都网站制作</a> | <a href="https://www.cdcxhl.com/cloud/" target="_blank">云服务器</a> | <a href="https://www.cdcxhl.com/weihu/abazhou.html" target="_blank">宜宾网站维护</a> | (宜宾网站建设QQ : 631063699 )</div> </footer> <!--在线咨询--> <div class="fot"> <ul> <li> <a href="mqqwpa://im/chat?chat_type=wpa&uin=532337155&version=1&src_type=web&web_src=oicqzone.com" target="_blank"> <img src="/Public/Home/img/fot1.png" alt="建站咨询"> <p>在线咨询</p> </a> </li> <li> <a href="tel:18980820575" target="_blank"> <img src="/Public/Home/img/fot2.png" alt="建站电话"> <p>拨打电话</p> </a> </li> </ul> </div> </body> </html> <script> $(".con img").each(function(){ var src = $(this).attr("src"); //获取图片地址 var str=new RegExp("http"); var result=str.test(src); if(result==false){ var url = "https://www.cdcxhl.com"+src; //绝对路径 $(this).attr("src",url); } }); window.onload=function(){ document.oncontextmenu=function(){ return false; } } </script>