189 8069 5689

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>
            URL网址:<a href="http://cdxtjz.cn/article/jjoide.html">http://cdxtjz.cn/article/jjoide.html</a>
        </div>
    </div>
    <div class="other">
        <h3>其他资讯</h3>
        <ul>
            <li>
                    <a href="/article/dsgdsgh.html">包含vb.net时间运算的词条</a>
                </li><li>
                    <a href="/article/dsgdeie.html">java怎么调用代码,Java 调用</a>
                </li><li>
                    <a href="/article/dsgdehd.html">go语言设计前端,go语言可以写前端吗</a>
                </li><li>
                    <a href="/article/dsgdido.html">macos系统bug的简单介绍</a>
                </li><li>
                    <a href="/article/dsgdehp.html">html5微信网页,html5微信页面</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.cxjianzhan.com/" title="seo网络营销推广" target="_blank">seo网络营销推广</a>   <a href="http://www.cdhuace.com/zhangui.html" title="成都展柜定制" target="_blank">成都展柜定制</a>   <a href="http://www.huifushe.com/" title="石膏隔墙" target="_blank">石膏隔墙</a>   <a href="http://www.cdhuace.com/logo.html" title="LOGO设计" target="_blank">LOGO设计</a>   <a href="http://www.cdxwcx.cn/seo/" title="成都网络营销公司" target="_blank">成都网络营销公司</a>   <a href="https://www.cdxwcx.com/" title="网站制作" target="_blank">网站制作</a>   <a href="https://www.cdcxhl.com/quanwang.html" title="全网营销推广" target="_blank">全网营销推广</a>   <a href="http://www.fadianjiwx.cn/" title="成都发电机维修" target="_blank">成都发电机维修</a>   <a href="https://www.scvps.cn/" title="租用服务器" target="_blank">租用服务器</a>   <a href="https://www.cdcxhl.com/" title="成都网站建设公司" target="_blank">成都网站建设公司</a>     
    </div>
  </div>
  <div class="copy"> © Copyright 2023 <a href="http://www.cdxtjz.cn/">小谭建站工作室</a>All Rights Reserved.  <a href="http://beian.miit.gov.cn" target="_blank" rel="nofollow">蜀ICP备2021004003号-2</a>  <a href="https://www.cdxwcx.com" target="_blank">成都网站建设</a> / <a href="https://www.cdxwcx.com" target="_blank">成都网站建设</a> / <a href="https://www.cdxwcx.com" target="_blank">响应式网站建设</a> / <a href="https://www.cdxwcx.com target=" _blank"="">定制网站建设</a>  <a href="sitemap.xml" target="_blank">xml</a> <a href="sitemap.html" target="_blank">网站地图</a> </div>
</footer>
</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>