jQuery实现的弹幕效果完整实例


Posted in jQuery onSeptember 06, 2017

本文实例讲述了jQuery实现的弹幕效果。分享给大家供大家参考,具体如下:

看视频的时候老是会出现一些弹幕,对于这个看着很高大上的特效,其实也不难实现。

先来看看运行效果:

jQuery实现的弹幕效果完整实例

下面将整个代码显示出来:

<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>3water.com弹幕</title>
<style type="text/css">
  html,body{
    background:#efefef;
    height:100%;
  }
  .danmu{
    width: 100px;
    height:30px;
    line-height: 28px;
    background: green;
    border-radius: 5px;
    border:1px solid #fff;
    color: #fff;
    outline: none;
  }
  div.mask{
    position:fixed;
    width:100%;
    height:100%;
    background:rgba(0,0,0,0.8);
    opacity:0.5;
    top:0px;
    left:0px;
  }
  div.bottom{
    width:100%;
    height:77px;
    background:linear-gradient(#ccc,#4a4a4a);
    position:fixed;
    bottom:0px;
    left:0px;
    text-align:center;
    line-height:77px;
  }
  div.bottom input.content{
    width:50%;
    min-width: 200px;
    height:37px;
    border:none;
    border-radius:10px 0px 0px 10px;
    font-size:16px;
    padding:0 10px;
    outline:none;
  }
  div.bottom a.send{
    background-color:green;
    color:#fff;
    display:inline-block;
    width:100px;
    height:38px;
    line-height:37px;
    text-align:center;
    position:relative;
    left:-10px;
    top:2px;
    border-radius:0px 10px 10px 0px;
    text-decoration:none;
    font-family:'Microsoft Yahei';
  }
  div.mask a.button{
    width:30px;
    height:30px;
    border-radius:50%;
    background-color:green;
    color:#fff;
    position:fixed;
    top:20px;
    right:20px;
    text-align:center;
    line-height:30px;
    font-size:20px;
    font-family:'Microsoft Yahei';
    border:1px solid #fff;
    text-decoration:none;
    cursor:pointer;
  }
  div.text{
    color:#fff;
    position:fixed;
    right:0px;
    font-size:20px;
    white-space: nowrap;
  }
</style>
</head>
<body>
<button class="danmu">弹幕技术</button>
  <div class="mask">
    <a href="#" rel="external nofollow" rel="external nofollow" class="button">X</a>
  </div>
  <!-- 底部发言框前端 -->
  <div class="bottom">
    <input class="content"></input>
    <a href="#" rel="external nofollow" rel="external nofollow" class="send">发表言论</a>
  </div>
  <script type="text/javascript" src="http://libs.baidu.com/jquery/2.0.0/jquery.min.js"></script>
  <script>
   $("a.send").click(function(){
  var val=$(".content").val();
  var content=$("<div class='text'>"+val+"</div>");
  var top=Math.random()*$(document.body).height()+40+"px";
  content.css("top",top);
  $(".mask").append(content);
  content.animate({right:$(document.body).width()+100},8000,function(){
  $(this).remove();
  })
  });
  $('.button').click(function(){
      $('div.mask').fadeOut(500);
    });
    $(".danmu").click(function(){
     $('div.mask').fadeIn(500);
  });
</script>
</body>
</html>

希望本文所述对大家jQuery程序设计有所帮助。

jQuery 相关文章推荐
jQuery插件FusionCharts绘制的3D环饼图效果示例【附demo源码】
Apr 02 jQuery
jQuery动态追加页面数据以及事件委托详解
May 06 jQuery
jquery单击文字或图片内容放大并居中显示
Jun 23 jQuery
jquery对table做排序操作的实例演示
Aug 10 jQuery
jQuery中 DOM节点操作方法大全
Oct 12 jQuery
Vue中正确使用jQuery的方法
Oct 30 jQuery
jQuery.Sumoselect插件实现下拉复选框效果
Nov 09 jQuery
jQuery与vue实现拖动验证码功能
Jan 30 jQuery
jQuery实现form表单序列化转换为json对象功能示例
May 23 jQuery
jQuery实现图片简单轮播功能示例
Aug 13 jQuery
jQuery实现获取多选框的值示例
Feb 07 jQuery
jQuery使用hide()、toggle()函数实现相机品牌展示隐藏功能
Jan 29 jQuery
jQuery实现的文字逐行向上间歇滚动效果示例
Sep 06 #jQuery
jquery实现限制textarea输入字数的方法
Sep 06 #jQuery
jquery实现用户登陆界面(示例讲解)
Sep 06 #jQuery
jQuery实现注册会员时密码强度提示信息功能示例
Sep 05 #jQuery
jquery+css实现下拉列表功能
Sep 03 #jQuery
jQuery中.attr()和.data()的区别分析
Sep 03 #jQuery
jQuery Ajax向服务端传递数组参数值的实例代码
Sep 03 #jQuery
You might like
php 对输入信息的进行安全过滤的函数代码
2012/06/29 PHP
php字符串截取的简单方法
2013/07/04 PHP
PHP+ajaxfileupload+jcrop插件完美实现头像上传剪裁
2014/06/09 PHP
php中解析带中文字符的url函数分享
2015/01/20 PHP
PHP中子类重载父类的方法【parent::方法名】
2016/05/06 PHP
PHP中Static(静态)关键字功能与用法实例分析
2019/04/05 PHP
Laravel 实现Eloquent模型分组查询并返回每个分组的数量 groupBy()
2019/10/23 PHP
doctype后如何获得body.clientHeight的方法
2007/07/11 Javascript
checkbox 复选框不能为空
2009/07/11 Javascript
javascript或asp实现的判断身份证号码是否正确两种验证方法
2009/11/26 Javascript
javascript动态添加表格数据行(ASP后台数据库保存例子)
2010/05/08 Javascript
CSS(js)限制页面显示的文本字符长度
2012/12/27 Javascript
javascript定义变量时有var和没有var的区别探讨
2014/07/21 Javascript
node.js中的fs.readdirSync方法使用说明
2014/12/17 Javascript
前端js文件合并的三种方式推荐
2016/05/19 Javascript
WEB 前端开发中防治重复提交的实现方法
2016/10/26 Javascript
vue省市区三联动下拉选择组件的实现
2017/04/28 Javascript
nodejs实现的连接MySQL数据库功能示例
2018/01/25 NodeJs
keep-Alive搭配vue-router实现缓存页面效果的示例代码
2020/06/24 Javascript
jQuery中getJSON跨域原理的深入讲解
2020/09/02 jQuery
js 将多个对象合并成一个对象 assign方法的实现
2020/09/24 Javascript
[01:57]2018DOTA2亚洲邀请赛赛前采访-iG
2018/04/03 DOTA
Python使用Pickle库实现读写序列操作示例
2018/06/15 Python
用python写一个定时提醒程序的实现代码
2019/07/22 Python
10行Python代码实现Web自动化管控的示例代码
2020/08/14 Python
Python通过队列来实现进程间通信的示例
2020/10/14 Python
简单的HTML5初步入门教程
2015/09/29 HTML / CSS
Gloeilampgoedkoop荷兰:在线购买灯泡
2019/02/16 全球购物
拉斯维加斯酒店、演出、旅游、俱乐部及更多:Vegas.com
2019/02/28 全球购物
GafasWorld西班牙:购买太阳镜、眼镜和隐形眼镜
2019/09/08 全球购物
优秀教师主要事迹
2014/02/01 职场文书
群众路线对照检查剖析材料
2014/10/09 职场文书
学雷锋感言
2015/08/03 职场文书
2016年教师节特级教师获奖感言
2015/12/09 职场文书
《绝招》教学反思
2016/02/20 职场文书
Django 如何实现文件上传下载
2021/04/08 Python