资讯

精准传达 • 有效沟通

从品牌网站建设到网络营销策划,从策略到执行的一站式服务

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://cdkjz.cn/article/gddseh.html">http://cdkjz.cn/article/gddseh.html</a>
        </div>
        <div class="g-return-wrapper clearfix">
            <a href="http://www.cdkjz.cn/" class="home">返回首页</a>
            <a href="http://www.cdkjz.cn/news/" class="column">了解更多建站资讯</a>
        </div>
    </div>
</div>
<div class="full-related-news">
    <h3 class="related-title">相关资讯</h3>
    <div class="related-news weblg">
        <ul class="clearfix">
            <li>
                    <a href="/article/dsophc.html">
                        <h2 class="title">基于红黑树插入操作原理及java实现的示例分析-创新互联</h2>
                    </a>
                </li><li>
                    <a href="/article/dsophj.html">
                        <h2 class="title">使用redis要注意什么-创新互联</h2>
                    </a>
                </li><li>
                    <a href="/article/dsopji.html">
                        <h2 class="title">jvm堆内存优化详解-创新互联</h2>
                    </a>
                </li><li>
                    <a href="/article/dsophh.html">
                        <h2 class="title">kkfileview手动docker部署-创新互联</h2>
                    </a>
                </li><li>
                    <a href="/article/dsohod.html">
                        <h2 class="title">学Go语言需要基础吗-创新互联</h2>
                    </a>
                </li><li>
                    <a href="/article/dsopge.html">
                        <h2 class="title">VMware网络连接模式指的是什么-创新互联</h2>
                    </a>
                </li><li>
                    <a href="/article/dsopeg.html">
                        <h2 class="title">『高级篇』docker之kubernetes基础集群部署(上)(33)-创新互联</h2>
                    </a>
                </li><li>
                    <a href="/article/dsopgo.html">
                        <h2 class="title">怎么用Python做一个久坐提醒小助手-创新互联</h2>
                    </a>
                </li>        </ul>
    </div>
</div>
<div class="full-icontact-cover m-ft-contact">
    <div class="weblg">
        <div class="clearfix content">
            <div class="motto">
                多年建站经验
            </div>
            <div class="info">
                <h3>多一份参考,总有益处</h3>
                <h2> 联系快上网,免费获得专属《策划方案》及报价</h2>
                <div class="msg">
                    <p>咨询相关问题或预约面谈,可以通过以下方式与我们联系</p>
                    <h4>业务热线:<a href="tel:400-028-6601" rel="nofollow">400-028-6601</a> / 大客户专线   成都:<a
                            href="tel:+13518219792" rel="nofollow">13518219792</a>
                          座机:<a href="tel:02886922220" rel="nofollow">028-86922220</a>
                    </h4>
                </div>
            </div>
        </div>
        <div class="btns clearfix">
            <a href="https://wpa.qq.com/msgrd?v=3&uin=631063699&site=qq&menu=yes" target="_blank" rel="nofollow"
               class="oline">在线咨询</a>
            <a href="javascript:;" class="edit" rel="nofollow">提交需求</a>
        </div>
    </div>
</div>
<div class="footer-content">
    <div class="weblg clearfix">
        <div class="friend-links">
            <h6 class="clearfix">
                <span class="tilte">友情链接</span>
                <a class="exchagne" href="http://wpa.qq.com/msgrd?v=3&uin=631063699&site=qq&menu=yes">交换友情链接</a>
            </h6>
            <div class="link-list clearfix">
                <div class="link-slider">
                    <a href="https://www.cdxwcx.com/wangzhan/app.html" title="移动APP" target="_blank">移动APP</a><a href="http://www.cdxwcx.cn/tuoguan/bgp.html" title="bgp机房托管" target="_blank">bgp机房托管</a><a href="https://www.cdxwcx.com/wangzhan/h5.html" title="h5响应式网站" target="_blank">h5响应式网站</a><a href="https://www.cdxwcx.com/city/dazhou/" title="达州做网站" target="_blank">达州做网站</a><a href="http://www.idckuai.cn/" title="云服务器" target="_blank">云服务器</a><a href="https://www.cdcxhl.com/pinpai.html" title="品牌网站建设" target="_blank">品牌网站建设</a><a href="http://m.cdxwcx.com/weihu.html" title="成都网站维护公司" target="_blank">成都网站维护公司</a><a href="https://www.xwcx.net/" title="托管服务器" target="_blank">托管服务器</a><a href="https://www.cdcxhl.com/idc/gysx.html" title="贵阳托管服务器" target="_blank">贵阳托管服务器</a><a href="https://www.cdcxhl.com/ssl/https.html" title="ssl证书申请" target="_blank">ssl证书申请</a>                </div>
            </div>
        </div>
    </div>
    <div class="full-foot-bottom">
        <div class="weblg clearfix">
            <p>成都网站建设公司地址:成都市青羊区太升南路288号锦天国际A座10层 建设咨询<a href="tel:400-028-6601">400-028-6601</a></p>
            <p>
                成都快上网科技有限公司-四川网站建设设计公司 | <a href="http://www.miitbeian.gov.cn/" target="_blank" rel="nofollow">蜀ICP备19037934号</a> Copyright 2020,ALL Rights Reserved cdkjz.cn | <a href="http://www.cdkjz.cn/" target="_blank">成都网站建设</a> | © Copyright 2020版权所有.</p>
            <p>专家团队为您提供<a href="http://www.cdkjz.cn/" target="_blank">成都网站建设</a>,<a href="http://www.cdkjz.cn/" target="_blank">成都网站设计</a>,成都品牌网站设计,成都营销型网站制作等服务,成都建网站就找快上网! | 成都网站建设哪家好? | <a href="###">网站建设地图</a></p>
        </div>
    </div>

</div>
<script type="text/javascript" src="../js/idangerous.swiper.min.js"></script>
<script type="text/javascript" src="../js/wow.min.js"></script>
<script type="text/javascript" src="../js/jquery.mousewheel.min.js"></script>
<script type="text/javascript" src="../js/jquery.placeholder.min.js"></script>
<script type="text/javascript" src="../js/layout.js"></script>
</body>
</html>
<script>
    $(".singlepage 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>