扩展代码|  常用工具|  常用框架|  站内项目|  常用地址|  代码规范| 关于我们

HTML实现弹幕技术

所属分类:Html

 2020-12-20 14:39  1503  0  2  0

打开弹幕

<a href="#" class="showBarrage">打开弹幕</a>

div

<div class="barrage">
<div class="screen">
<a href="#" class="s_close">X</a>
<div class="mask">
<!--内容在这里显示-->
</div>
</div>
<!--Send Begin-->
<div class="send">
<input type="text" class="s_text"/>
<input type="button" class="s_btn" value="说两句"/>
</div>
<!--Send End-->
<span class="s_close">X</span>
</div>

css

.barrage .screen{width:100%;height:100%;position:absolute;top:0px;right:0px;}
.barrage .screen .s_close{z-index:2;top:20px;right:20px;position:absolute;text-decoration:none;width:40px;height:40px;border-radius:20px;text-align:center;color:#fff;background:#000;line-height:40px;display:none;}
.barrage .screen .mask{position:relative;width:100%;height:100%;background:#000;opacity:0.5;filter:alpha(opacity:1);z-index:1;}
.barrage{display:none;width:100%;height:100%;}
.barrage .screen .mask div{position:absolute;font-size:20px;font-weight:bold;white-space:nowrap;line-height:40px;z-index:40;}
.barrage .send{z-index:1;width:100%;height:55px;background:#000;position:absolute;bottom:0px;text-align:center;}
.barrage .send .s_text{width:600px;height:40px;line-height:10px;font-size:20px;font-family:"微软雅黑";}
.barrage .send .s_btn{width:105px;height:40px;background:#22B14C;color:#fff;}

js

<script src="js/jquery-1.11.1.min.js"></script>
<script>
$(function(){
$(".showBarrage,.s_close").click(function(){
$(".barrage,.s_close").toggle("slow");
});
init_animated();
})
//提交评论
$(".send .s_btn").click(function(){
var text = $(".s_text").val();
if(text == ""){
return;
};
var _lable = $("<div style='right:20px;top:0px;opacity:1;color:"+getRandomColor()+";'>"+text+"</div>");
$(".mask").append(_lable.show());
init_barrage();
})
//初始化弹幕技术
function init_barrage(){
var _top = 0;
$(".mask div").show().each(function(){
var _left = $(window).width()-$(this).width();//浏览器最大宽度,作为定位left的值
var _height = $(window).height();//浏览器最大高度
_top +=75;
if(_top >= (_height -130)){
_top = 0;
}
$(this).css({left:_left,top:_top,color:getRandomColor()});
//定时弹出文字
var time = 10000;
if($(this).index() % 2 == 0){
time = 15000;
}
$(this).animate({left:"-"+_left+"px"},time,function(){
$(this).remove();
});
}
);
}
//获取随机颜色
function getRandomColor(){
return '#' + (function(h){
return new Array(7 - h.length).join("0") + h
}
)((Math.random() * 0x1000000 << 0).toString(16))

}

</script>  

如有帮助请打赏一下,分分是爱!!!
微信打赏
相关分类推荐
css使div旋转90度

css使div旋转90度

css使div旋转90度
  Html
 4120  1  2
html遮罩层

html遮罩层

html遮罩层,弹出默认提示框的时候背景遮罩
  Html
 1550  1  1
h5-html全屏

h5-html全屏

全屏API requestFullscreen方法在一些老的浏览器里面依然使用带前缀形式的方法名,因此可能需要进行检测判断。
  Html
 1776  0  0
Vue使用2.文件目录结构讲解

Vue使用2.文件目录结构讲解

Vue.js(读音 /vjuː/, 类似于 view) 是一套构建用户界面的渐进式框架。 Vue 只关注视图层, 采用自底向上增量开发的设计。 Vue 的目标是通过尽可能简单的 API 实现响应的数据绑定和组合的视图组件。 Vue 学习起来非常简单,本教程基于 Vue 2.1.8 版本测试。
  Html
 976  0  0

评论这篇文章(0

  • 楼主 xcSharp博客
学习永无止境,活到老,学到老,书山有路勤为径,学海无涯苦作舟;业精于勤荒于喜,行成于思毁于随