1.首先上图看下效果

2.废话不多说,直接上代码

1>html代码

<div class="barrage">

<div class="screen">
<div class="content">
<!--内容在这里显示-->
</div>
</div>
<!--发送对话框-->
<div class="send">
<input type="text" class="s_text" placeholder="使用回车可以快速发送弹幕"/>
<input type="button" class="s_btn" value="发送" />
<!--关闭弹幕功能-->
<span class="barrage_close">关闭弹幕</span>
</div>
</div>
 
 
2>css部分
*{

padding: 0;
margin: 0;
}
input{
outline: none;
}
.barrage .screen {
width: 100%;
height: 100%;
position: absolute;
top: 0px;
right: 0px;
background: url(../img/1.jpg);
background-size: cover;
}
.barrage .screen .content {
position: relative;
width: 100%;
height: 100%;
background: #000;
opacity:0.5;
/* filter: alpha(opacity=100); *//***针对ie8以上或者更早的浏览器****/
background-color: transparent;
z-index: 1;
}
.barrage {
 
width: 100%;
height: 100%;
}
.barrage .screen .content 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;
line-height: 55px;
background: #000;
position: absolute;
bottom: 0px;
text-align: center;
}
.barrage .send .s_text {
width: 600px;
height: 40px;
line-height: 40px;
font-size: 16px;
font-family: "微软雅黑";
border-radius:20px;;
}
.barrage .send .s_btn {
width: 105px;
height: 40px;
background: #22B14C;
color: #fff;
border-radius: 10px;
}
.barrage_close {
position: absolute;
right:210px;
bottom:10px;
width: 80px;
height: 20px;
border-radius: 10px;
text-align: center;
line-height: 20px;
color: #22B14C;
background: #fff;
z-index: 99;
}
.barrage_close1{
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 () {

// $(".s_close").click(function () {
// $(".barrage").toggle("slow");
// });
// $(".barrage_close").toggle(function(){
// })
// init_animated();
init_barrage();
})
//将弹幕内容放进数组贮存起来
//var arr=[];
//var h=arr.push()
// 监听发送,按enter发送
document.onkeydown=function(event){
var e = event || window.event;
if(e && e.keyCode==13){
// console.log(11111);
$(".send .s_btn").click();
}
}
//提交评论
$(".send .s_btn").click(function () {
var text = $(".s_text").val();
if (text == "") {
alert('你的内容为空,请填写评论在再发送');
return false;
};
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 = $(window).width() - $(this).width();//浏览器最大宽度,作为定位left的值
var _height = $(window).height();//浏览器最大高度
_top += 75;
if (_top >= (_height - 130)) {
_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))
}
 
 

利用css和jquery制成弹幕的更多相关文章

  1. 利用js和JQuery定义一个导航条菜单

    利用js和JQuery定义一个导航条 效果: 一.html代码: <div class="Maintenance"> <div class="Title ...

  2. 利用HTML5与jQuery技术创建一个简单的自动表单完成

    来源:GBin1.com 在线演示   在线下载 谷歌快速搜索自带大量自动完成插件——库中甚至还有一个附带的jQuery UI共享选项.然而今天我要寻找一个替代的解决方案.由DevBridge开发的j ...

  3. css与jquery、图标字体

    *)还能这样选择 header #search input[type="text"] *)按钮常用颜色:#008cBA(字母大小写没有区别) *)清除浮动后,text-align没 ...

  4. CSS与JQuery的相关问题

    文字隐藏:p div里面的文字过长时隐藏文字: overflow:hidden; text-overflow:ellipsis; white-space:nowrap; --------------- ...

  5. 利用CSS实现带相同间隔地无缝滚动动画

    说明:因为在移动上主要利用CSS来做动画,所以没有考虑其他浏览器的兼容性,只有-webkit这个前缀,如果需要其他浏览器,请自行补齐. 首先解释一下什么是无缝滚动动画, 例如下面的例子 See the ...

  6. 使用CSS和jQuery实现对话框

    因为项目中要显示一些对话框,但用alert显得太丑,后从网上找了一些插件,但有觉得不好用,因此自己试用CSS和jQuery写了一个对话框,代码如下: <!DOCTYPE html> < ...

  7. 使用CSS和jQuery实现tab页

    使用jquery来操作DOM是极大的方便和简单,这儿只是简单的用一个使用css和jquery来实现的tab页来简单介绍一些jQuery的一些方便使用的方法,下面是html文件: <!DOCTYP ...

  8. 如何利用CSS代码使图片和文字在同一行显示且对齐

    对于初学css的新手朋友来说,经常会遇到这样一个问题,当文字和图片出现在同一行或者同一个div里面的时候,在浏览器中运行出来的显示效果往往是在不同的行,那么,我们怎么才能利用CSS代码使图片和文字在同 ...

  9. Web前端开发如何利用css样式来控制Html中的h1/h2/h3标签不换行

      H1/H2/H3/H4标题标签常常使用在一个网页中唯一标题.重要栏目.重要标题等情形下. H1在一个网页中最好只使用一次,如对一个网页唯一标题使用.H2.H3.H4标签则可以在一个网页中多次出现, ...

随机推荐

  1. 【APIO2019】桥梁(询问分块)

    Description 给定一张 \(n\) 个点,\(m\) 条边的无向图,边 \(i\) 的权值为 \(d_i\).现有 \(q\) 次操作,第 \(j\) 个操作有两种模式: \(1\ b_j\ ...

  2. nginx学习之——信号控制和配置

    一.信号控制 1)TERM, INT   Quick shutdown  \\麻溜停掉(暴力停止),一般不常用 // 启动和停止nginx 当前目录:/usr/local/bin/nginx 启动: ...

  3. JAVA获取指定的类型的本机MAC地址

    前面我们运维小伙在部署的时候,发现在真实服务器获取不到mac地址或者获取不到指定类型的mac地址,写程序记录如下 import com.google.common.base.Strings; impo ...

  4. STM32系统时钟RCC(基于HAL库)

    基础认识 为什么要有时钟: 时钟就是单片机的心脏,其每跳动一次,整个单片机的电路就会同步动作一次.时钟的速率决定了两次动作的间隔时间.速率越快,单片机在单位时间内所执行的动作将越多.时钟是单片机运行的 ...

  5. 使用tkinter打造一个小说下载器,想看什么小说,就下什么

    前言 今天教大家用户Python GUI编程--tkinter 打造一个小说下载器,想看什么小说,就下载什么小说 先看下效果图 Tkinter 是使用 python 进行窗口视窗设计的模块.Tkint ...

  6. pyhon 自动化 logger

    #!/Users/windows8.1/PycharmProjects/pythonapi# @Software: PyCharm Community Edition# -*- coding: utf ...

  7. JavaSE01-概述

    1.1 Java语言发展史 语言:人与人交流沟通的表达方式 计算机语言:人与计算机之间进行信息交流沟通的一种特殊语言 Java语言是美国Sun公司(Stanford University Networ ...

  8. 基于nacos注册中心的ribbon定制规则

    前面说到基于nacos的注册发现有可以扩展实现我们自己的负载均衡算法(Nacos数据模型),来实现同集群调用,是基于spring.cloud.nacos.discovery.cluster-name参 ...

  9. 事件修饰符 阻止冒泡 .stop 阻止默认事件 .prevent

    stop修饰符 阻止冒泡行为 可以在函数中利用$event传参通过stopPropagation()阻止冒泡 通过直接在元素中的指令中添加 .stop prevent修饰符 阻止默认行为 可以在函数中 ...

  10. OkHttpClient调优案例

    OkHttpClient调优案例 作者:Grey 原文地址: 语雀 博客园 Github 实际案例 系统运行一段时间后,线程数量飙升,CPU持续居高不下 排查工具 https://fastthread ...