• 首页
  • 美文阅读
  • 美文鉴赏
  • 英文翻译
  • 范文
  • 作文
  • 实用文体
  • 诗词歌赋
  • 英语园地
  • 组词大全
  • 优秀作文
  • 诗歌大全
  • 试题
  • 专利检索
  • 知识大全

 首页 > 作文

HTML5实现视频弹幕功能

更新时间:2023-04-07 04:12:18 阅读: 评论:0

1.首先展示一下弹幕视频弹幕原图,事实说话

2.代码展示

1>html代码展示

<div class="barrage">        <video id="myvideo" autoplay loop width="100%" height="300px">            <source src="video/1.mp4">        </video>        <div class="screen">            <div class="content">                <!--内容在这里显示-->            </div>        </div>        <!--发送对话框-->        <div class="nd">            <input type="text" class="s_text" placeholder="使用回车可以快速发送弹幕"/>            <inp花千骨轻水ut type="button" class="s_btn" value="发送" />             <!--关闭弹幕功能-->            <span class="barrage_clo">关闭弹幕</span>            <!-- 静音功能  -->            <span id="muted">开启静音</span>        </div>  </div>

2>css代码展示

*{    padding: 0;    margin: 0;}input{    outline: none;}.barrage {    position: relative;    width: 100%;    height:250px;}#myvideo{    position: absolute;    /* width: 100%;    height:300px; */    top: -50px;    left: 0;    z-index: -1;}.barrage .screen {    position: absolute;    top: 0px;    right: 0px;    width: 100%;    height: 300px;}.barrage .screen .content {    position: relative;    width: 100%;    height: 250px;    background: #000;    opacity:0.5;    /* filter: alpha(opacity=100); *//***针对ie8以上或者更早的浏览器****/    background-color: transparent;    z-index: 1;}.barrage .screen .content div {    position: absolute;    font-size: 20px;    font-weight: bold;    white-space: nowrap;    line-height: 40px;    z-index: 40;}.barrage .nd {    position: absolute;    bottom: 0px;    width: 100%;    height: 55px;    line-height: 55px;    z-index: 1;    /*background: #000;*/    backgroun四个晚上d: rgba(0,0,0,0.5);    text-align: center;    /*display: none;*/}.barrage:hover .nd{    display: block;}.barrage .nd .s_text {    width: 60%;    height: 35px;    line-height:35px;    font-size: 16px;    font-family: "微软雅黑";    border-radius:20px;    opacity: 0.8;}.barrage .nd .s_btn {    width: 105px;    height: 35px;    line-height: 35px;    background: #22b14c;    color: #f不可分割ff;    border-radius: 10px;    opacity: 0.8;}.barrage_clo,#muted {    width: 80px;    height: 30px;    line-height: 30px;    border-radius: 10px;    text-align: center;    color: #22b14c;    background:#fff;    cursor: pointer;    opacity: 0.8;}#muted{    background:yellow;}.barrage_clo1{    color: #fff;    background: #fff;}/* css动画 */.content div{    animation:text 15s infinite normal;}@keyframes text{    0%{        left:100%;    }  取类比象  20%{        left:75%;    }    80%{        left:0%;    }    100%{        left:-30%;    }}

3>js代码展示

$(function () {     $(".barrage_clo").click(function(){         $(".content div").remove();     });    init_barrage();});//将弹幕内容放进数组贮存起来var arr=[];var h=arr.push();// 监听发送,按enter发送document.οnkeydοwn=function(event){    var e = event || window.event;    if(e && e.keycode==13){     //    console.log(11111);        $(".nd .s_btn").click();    }                };//提交评论$(".nd .s_btn").click(function () {    var text = $(".s_text").val();    if (text == "") {        alert('你的内容为空,请填写评论在再发送');        return fal;    }    var _lable = $("<div style='right:20px;top:0px;opacity:1;color:" + getcolor() + ";'class='content_text'>" + text + "</div>");    $(".content").append(_lable.show());    init_barrage();    $(".s_text").val("");});//初始化弹幕技术function init_barrage() {    var _top = 0;    $(".content div").show().each(function () {        var _left =$(".barrage").width();//浏器览最大宽度(也是浏览器的高度),作为定位left的值        console.log(_left);        var _height =$(".barrage").height();//视频窗口的最大高度        console.log(_height);        _top += 35;        if (_top >= (_height - 150)) {            _top = 0;        }        $(this).css({ left: _left, top: _top, color: getcolor() });        //定时弹出文字        // var time = 10000;        // if ($(this).index() % 2 == 0) {        //     time = 15000;        // }        // $(this).animate({ left: "-" + _left + "px" }, time, function () {        //     $(this).remove();        // });    });}//获取随机颜色function getcolor() {    return '#' + (function (h) {        return new array(7 - h.length).join("0") + h    })    ((math.random() * 0x1000000 << 0).tostring(16))}var video=document.getelementbyid("myvideo");var mute=document.getelementbyid("muted");console.log(muted);//设置视频播放速度// video.playbackrate = 0.5;//视频静音video.muted = fal;mute.οnclick=function(){    if(video.muted){                video.muted = fal;                   mute.innertext='';                mute.innertext = '开启静音';                // console.log(1111)            }el{                video.muted = true;                   mute.innertext='';                mute.innertext = '关闭静音';                // console.log(2222)            }}

3.代码效果演示

<a title="查看演示效果" href="https://leader755.github.io/video-barrage/" target="_blank" >点我查看演示效果</a><a title="下载源码" href="/d/file/titlepic/video-barrage" target="_blank">点我下载源码</a>

4.最重要的一点别忘了

问题:视频宽度不能100%,高度我定死了300px,有哪位大神帮吗解决一下吧。以下为涉及的主要代码,可以上翻查看详细代码。

<div class="barrage">            <video id="myvideo" autoplay loop width="100%" height="300px">                <source src="video/1.mp4">            </video></div><style>   .barrage {    position: relative;    width: 100%;    height:250px;}#myvideo{    position: absolute;    /* width: 100%;    height:300px; */    top: -50px;    left: 0;    z-index: -1;}</style>

总结

以上所述是www.887一句暖心的话551.com给大家介绍的html5实现视频弹幕功能 ,希望对大家有所帮助

本文发布于:2023-04-07 04:12:14,感谢您对本站的认可!

本文链接:https://www.wtabcd.cn/fanwen/zuowen/dae48ff4c817469e7e00364a3ae84b83.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

本文word下载地址:HTML5实现视频弹幕功能.doc

本文 PDF 下载地址:HTML5实现视频弹幕功能.pdf

上一篇:孕期贫血不吃药可以吗
下一篇:返回列表
标签:静音   代码   弹幕   视频
相关文章
留言与评论(共有 0 条评论)
   
验证码:
推荐文章
排行榜
  • HTML5实现视频弹幕功能
    1.首先展示一下弹幕视频弹幕原图,事实说话2.代码展示1>html代码展示
  • 0℃孕期贫血不吃药可以吗
  • 0℃勺子课堂完成A+轮3000万元人民币融资
  • 0℃PHP编实现程动态图像的创建
  • 0℃vivo手机怎么给手机加速
  • 0℃html5 canvas实现给图片添加平铺水印
  • 0℃解决RHAS3中Apache2的PHP上传文件大小的限制
  • 0℃用php发送带附件的Email
  • 0℃博雅辑因完成亿元Pre
  • 0℃婴儿湿疹影响吃奶吗
热门标签
  • 成语
  • 的是
  • 形容
  • 范文
  • 句子
  • 有哪些
  • 工作总结
  • 工作计划
  • 合同范本
  • 反义词
  • 什么意思
  • 的人
  • 自己的
  • 讲话
  • 大全
  • 都是
  • 生长
  • 材料
  • 还不
  • 英语
  • 土壤
  • 孩子
  • 中国
  • 函数
  • 很多人
  • 工作
  • 放在
  • 我是
  • 方法
  • 植株
  • 合集
  • 优秀
  • 这一
  • 语文
  • 最新
  • 风水
  • 报告
  • 学校
  • 时间
  • 疫情
Copyright ©2019-2022 Comsenz Inc.Powered by © 专利检索| 网站地图
  • 我要关灯
    我要开灯
  • 返回顶部