該文章短小精悍
問?視頻全屏後如何加彈幕
答:瞭解一下 screenfull; pointer-events: none;
(若是你沒有領會個人意思,我能夠手摸手帶你擼一遍)css
WEY?
html
4.錯在了哪裏git
這個問題若是思路錯了就是個死衚衕。因此我在找問題的時候趟了不少坑。思路錯在我不該該使用視頻的全屏,敲黑板!劃重點啦!不要使用視頻的全屏!(解決了問題的時候才幡然醒悟),而後發現了個賊有意思的東西。[screenfull][3]。不知道B站他們怎麼玩的,可是我用這個實現了。這個東西作了一個事情讓你瀏覽器的DOM鋪滿全屏。歐?~~~
5 實現它
DOMgithub
<div class='player' id='vb'> <video id='vd' playsinline webkit-playsinline="true" controls style='object-fit: contain;'> <source src="http://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4" type="video/mp4" /> </video> <div class='video-status' id='log'> <img src="http://wx4.sinaimg.cn/large/006ARE9vgy1fs9w9ukwjhj30g40afaap.jpg" alt=""> </div> </div>
Scriptweb
<script src="https://cdn.bootcss.com/screenfull.js/4.1.0/screenfull.js"></script> <script> const log = document.getElementById('log') const videoBox = document.getElementById('vb') log.onclick = _=> { const fullFlag = videoBox.className.indexOf('full-screen') if (fullFlag === -1) { videoBox.setAttribute('class', 'player full-screen') } else { videoBox.setAttribute('class', 'player') } screenfull.toggle() } </script>
CSS瀏覽器
<style> /* reset */ html,body,h1,h2,h3,h4,h5,h6,div,dl,dt,dd,ul,ol,li,p,blockquote,pre,hr,figure,table,caption,th,td,form,fieldset,legend,input,button,textarea,menu{margin:0;padding:0;} header,footer,section,article,aside,nav,hgroup,address,figure,figcaption,menu,details{display:block;} table{border-collapse:collapse;border-spacing:0;} caption,th{text-align:left;font-weight:normal;} html,body,fieldset,img,iframe,abbr{border:0;} i,cite,em,var,address,dfn{font-style:normal;} [hidefocus],summary{outline:0;} li{list-style:none;} h1,h2,h3,h4,h5,h6,small{font-size:100%;} sup,sub{font-size:83%;} pre,code,kbd,samp{font-family:inherit;} q:before,q:after{content:none;} textarea{overflow:auto;resize:none;} label,summary{cursor:default;} a,button{cursor:pointer;} h1,h2,h3,h4,h5,h6,em,strong,b{font-weight:bold;} del,ins,u,s,a,a:hover{text-decoration:none;} body,textarea,input,button,select,keygen,legend{font:12px/1.14 arial,\5b8b\4f53;color:#333;outline:0;} body{background:#fff;} a,a:hover{color:#333;} .player { width: 800px; height: auto; margin: 0 auto; position: relative; background-color: black; } .player video{ width: 100%; height: 100%; } .video-status { position: absolute; right: 100px; top: 40px; } .video-status img { width: 100px; } .full-screen { position: fixed; width: 100%; height: 100%; } </style>
去個人代碼裏找你須要的東西吧。ide
6.pointer-events是啥?彈幕呢?spa
pointer-events 是一個CSS屬性作點透的時候用的,若是你有一個彈幕層在Video上邊你會須要到她的。彈幕呢,沒有。好多人都已經實現了好很差,這個你仍是去問問[百度][5]或者[必應][6]吧。
GitHub 地址 https://github.com/Gao-Fan/vi...3d