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实现的MSBar3D图效果示例【附demo源码】
Mar 23 jQuery
各种选择框jQuery的选中方法(实例讲解)
Jun 27 jQuery
jQuery实现拼图小游戏(实例讲解)
Jul 24 jQuery
jquery在vue脚手架中的使用方式示例
Aug 29 jQuery
jQuery实现倒计时功能 jQuery实现计时器功能
Sep 19 jQuery
jQuery响应滚动条事件功能示例
Oct 14 jQuery
jquery学习笔记之无new构建详解
Dec 07 jQuery
jquery的 filter()方法使用教程
Mar 22 jQuery
JQuery Ajax动态加载Table数据的实例讲解
Aug 09 jQuery
使用jquery模拟a标签的click事件无法实现跳转的解决
Dec 04 jQuery
Jquery Datatables的使用详解
Jan 30 jQuery
jquery实现拖拽小方块效果
Dec 10 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
解析mysql中UNIX_TIMESTAMP()函数与php中time()函数的区别
2013/06/24 PHP
php使用curl打开https网站的方法
2015/06/17 PHP
thinkPHP+ajax实现统计页面pv浏览量的方法
2017/03/15 PHP
Laravel框架实现抢红包功能示例
2019/10/31 PHP
在textarea中显示html页面的javascript代码
2007/04/20 Javascript
基于jquery循环map功能的代码
2011/02/26 Javascript
javascript将相对路径转绝对路径示例
2014/03/14 Javascript
JS的事件绑定深入认识
2014/06/26 Javascript
利用JS实现点击按钮后图片自动切换的简单方法
2016/10/24 Javascript
关于Vue.js一些问题和思考学习笔记(2)
2016/12/02 Javascript
详解jQuery uploadify文件上传插件的使用方法
2016/12/16 Javascript
微信小程序 摇一摇抽奖简单实例实现代码
2017/01/09 Javascript
JS实现直接运行html代码的方法
2017/03/13 Javascript
强大的 Angular 表单验证功能详细介绍
2017/05/23 Javascript
centos 上快速搭建ghost博客方法分享
2018/05/23 Javascript
Javascript中parseInt的正确使用方式
2018/10/17 Javascript
react同构实践之实现自己的同构模板
2019/03/13 Javascript
vue.js多页面开发环境搭建过程
2019/04/24 Javascript
Python中用startswith()函数判断字符串开头的教程
2015/04/07 Python
Pythont特殊语法filter,map,reduce,apply使用方法
2016/02/27 Python
Python实现GUI学生信息管理系统
2020/04/05 Python
解决python中 f.write写入中文出错的问题
2018/10/31 Python
windows下安装Python虚拟环境virtualenvwrapper-win
2019/06/14 Python
解决pycharm运行程序出现卡住scanning files to index索引的问题
2019/06/27 Python
django一对多模型以及如何在前端实现详解
2019/07/24 Python
在python Numpy中求向量和矩阵的范数实例
2019/08/26 Python
Dockers美国官方网站:卡其裤、男士服装、鞋及配件
2016/11/22 全球购物
伦敦一家西班牙童装精品店:La Coqueta
2018/02/02 全球购物
自荐信包含哪些内容
2013/10/30 职场文书
团组织关系介绍信
2014/01/12 职场文书
教师产假请假条范文
2014/04/10 职场文书
给校长的建议书600字
2014/05/15 职场文书
团干部培训方案
2014/06/03 职场文书
地道战观后感400字
2015/06/04 职场文书
员工聘用合同范本
2015/09/21 职场文书
高一数学教学反思
2016/02/18 职场文书