站长资源网页制作

HTML5 视频播放(video),JavaScript控制视频的实例代码

整理:jimmy2025/1/6浏览2
简介具体代码如下所示: Documenttitle><style>figcaption {text-align: center;line-height: 150px;font-fami</div> <div class="news_infos"><div id="MyContent"><p>具体代码如下所示:</p> <p> </p> <div class="htmlcode"> <pre class="brush:xhtml;"> <html lang="en"> <head> <meta charset="UTF-8"> <title>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> </div> <p><strong>总结</strong></p> <p>以上所述是小编给大家介绍的HTML5 视频播放(video),JavaScript控制视频的实例代码,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对网站的支持!</p></div> </div> </div> <div class="share"> </div> <div class="nextinfo"> <p>上一篇:<a href="/3g/1/68873.html" title="HTML5实现签到 功能 ">HTML5实现签到 功能 </a></p> <p>下一篇:<a href="/3g/1/68875.html" title="移动端html5模拟长按事件的实现方法">移动端html5模拟长按事件的实现方法</a></p> </div> <div class="otherlink"> <h2>最新资源</h2> <ul> <li><a href="/3g/1/623703.html" title="群星《奔赴!万人现场 第2期》[FLAC/分轨]">群星《奔赴!万人现场 第2期》[FLAC/分轨]</a></li> <li><a href="/3g/1/623702.html" title="群星《奇妙浪一夏 (上海迪士尼度假区音乐">群星《奇妙浪一夏 (上海迪士尼度假区音乐</a></li> <li><a href="/3g/1/623701.html" title="群星《奇妙浪一夏 (上海迪士尼度假区音乐">群星《奇妙浪一夏 (上海迪士尼度假区音乐</a></li> <li><a href="/3g/1/623700.html" title="【古典音乐】詹姆斯·高威《季节》1993[WA">【古典音乐】詹姆斯·高威《季节》1993[WA</a></li> <li><a href="/3g/1/623699.html" title="贝拉芳蒂《卡里普索之王》SACD[WAV+CUE]">贝拉芳蒂《卡里普索之王》SACD[WAV+CUE]</a></li> <li><a href="/3g/1/623698.html" title="小骆驼-《草原狼2(蓝光CD)》[原抓WAV+CUE">小骆驼-《草原狼2(蓝光CD)》[原抓WAV+CUE</a></li> <li><a href="/3g/1/623697.html" title="群星《欢迎来到我身边 电影原声专辑》[32">群星《欢迎来到我身边 电影原声专辑》[32</a></li> <li><a href="/3g/1/623696.html" title="群星《欢迎来到我身边 电影原声专辑》[FL">群星《欢迎来到我身边 电影原声专辑》[FL</a></li> <li><a href="/3g/1/623695.html" title="雷婷《梦里蓝天HQⅡ》 2023头版限量编号低">雷婷《梦里蓝天HQⅡ》 2023头版限量编号低</a></li> <li><a href="/3g/1/623694.html" title="群星《2024好听新歌42》AI调整音效【WAV分">群星《2024好听新歌42》AI调整音效【WAV分</a></li> </ul> </div> </div> <div class="sidebar"> <div class="cloud"><h2 class="hometitle">标签云</h2><ul><a href="/search.asp?key=1080P高清&m=1">1080P高清<span>(5)</span></a><a href="/search.asp?key=高清电影&m=1">高清电影<span>(5)</span></a><a href="/search.asp?key=百度云盘&m=1">百度云盘<span>(5)</span></a><a href="/search.asp?key=网盘下载&m=1">网盘下载<span>(4)</span></a><a href="/search.asp?key=破解软件&m=1">破解软件<span>(4)</span></a><a href="/search.asp?key=绿色软件&m=1">绿色软件<span>(4)</span></a><a href="/search.asp?key=磁力链接&m=1">磁力链接<span>(3)</span></a><a href="/search.asp?key=强度天梯&m=1">强度天梯<span>(3)</span></a><a href="/search.asp?key=福利资源&m=1">福利资源<span>(2)</span></a><a href="/search.asp?key=王者荣耀&m=1">王者荣耀<span>(2)</span></a><a href="/search.asp?key=黑钻活动&m=1">黑钻活动<span>(2)</span></a><a href="/search.asp?key=WPS会员&m=1">WPS会员<span>(2)</span></a><a href="/search.asp?key=刷图排行&m=1">刷图排行<span>(1)</span></a><a href="/search.asp?key=网盘限速&m=1">网盘限速<span>(1)</span></a><a href="/search.asp?key=鬼灭之刃&m=1">鬼灭之刃<span>(1)</span></a><a href="/search.asp?key=免费韩国漫画&m=1">免费韩国漫画<span>(1)</span></a><a href="/search.asp?key=宫本重做&m=1">宫本重做<span>(1)</span></a><a href="/search.asp?key=免费动漫&m=1">免费动漫<span>(1)</span></a></ul></div> </div> <div class="sidebar"> 友情链接:<a href="http://www.imxmx.com/" title="杰晶网络" target="_blank">杰晶网络</a> <a href="/" title="DDR爱好者之家" target="_blank">DDR爱好者之家</a> <a href="http://www.nqxw.com/" title="南强小屋" target="_blank">南强小屋</a> <a href="http://www.paidiu.com/" title="黑松山资源网" target="_blank">黑松山资源网</a> <a href="http://www.dyhadc.com/" title="白云城资源网" target="_blank">白云城资源网</a> <a href="/sitemap1.xml">站点地图</a> <a href="/sitemap.xml">SiteMap</a> </div> </article> <footer> <p>Design by <a href="http://m.ddrfans.com">DDR爱好者之家</a> <a href="http://m.ddrfans.com">http://m.ddrfans.com</a></p> </footer> <script src="/images3g/nav.js"></script> <script type="text/javascript"> jQuery.noConflict(); jQuery(function() { var elm = jQuery('#left_flow2'); var startPos = jQuery(elm).offset().top; jQuery.event.add(window, "scroll", function() { var p = jQuery(window).scrollTop(); jQuery(elm).css('position', ((p) > startPos) ? 'fixed' : ''); jQuery(elm).css('top', ((p) > startPos) ? '0' : ''); }); }); </script> </body> </html>