视频全屏弹幕实现

该文章短小精悍
问?视频全屏后如何加弹幕
答:了解一下 screenfull; pointer-events: none;
(若是你没有领会个人意思,我能够手摸手带你撸一遍)css

图片描述

  1. 视频全屏遇到的问题
    最近在搞给视频加个花边的东西用的 Flash,在全屏的时候浏览器会把视频层级提升(H5也有一样的问题),(重点是 Flash 并不草理你的DOM,你们玩玩就懂个人意思了。)致使全屏后经过position定位的花边位于了视频下方,简单的说花边在视频全屏的时候不展现
  2. 处理问题的过程
    最开始用的是很是常规的想法,如何在视频全屏的时候下降视频的层级,使我须要的div块位于视频上方。而后尝试了各类方法,结果被制裁的服服帖帖的,你们能够去搞搞。其实仔细思考我要作的就是相似于弹幕的东西,咦~~B站怎么实现的。
  3. 别人家的弹幕
    B站确定是拿不到源码的啦,缕他控制台的资源,element,style。人家确实全屏的时候实现了,弹幕
    写的DOM结构,和CSS样式并不复杂,全屏无外乎全屏的时候给DOM加了一个样式而已。我也照着试了不行。

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

相关文章
相关标签/搜索