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自定义元素右键点击事件(实现案例)
Apr 28 jQuery
jquery对table做排序操作的实例演示
Aug 10 jQuery
jQuery EasyUI开发技巧总结
Sep 26 jQuery
jQuery实现获取table中鼠标click点击位置行号与列号的方法
Oct 09 jQuery
jQuery创建及操作xml格式数据示例
May 26 jQuery
jQuery实现的页面详情展开收起功能示例
Jun 11 jQuery
jQuery超简单遮罩层实现方法示例
Sep 06 jQuery
JS/jQuery实现简单的开关灯效果【案例】
Feb 19 jQuery
jquery实现二级导航下拉菜单效果实例
May 14 jQuery
基于jquery实现彩色投票进度条代码解析
Aug 26 jQuery
jquery插件实现搜索历史
Apr 24 jQuery
html中两种获取标签内的值的方法
Jun 16 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实现paypal整合方法
2010/11/28 PHP
PHP父类调用子类方法的代码例子
2014/04/09 PHP
PHP扩展模块memcached长连接使用方法分析
2014/12/24 PHP
PHP+ajax实现二级联动菜单功能示例
2018/08/10 PHP
用js实现多域名不同文件的调用方法
2007/01/12 Javascript
js弹出层永远居中实现思路及代码
2013/11/29 Javascript
使用jQuery快速解决input中placeholder值在ie中无法支持的问题
2014/01/02 Javascript
node.js实现逐行读取文件内容的代码
2014/06/27 Javascript
深入理解Javascript中this的作用域
2014/08/12 Javascript
js实现文本框只允许输入数字并限制数字大小的方法
2015/08/19 Javascript
利用js+css+html实现固定table的列头不动
2016/12/08 Javascript
jQuery中Datatables增加跳转到指定页功能
2017/02/08 Javascript
Vue.js展示AJAX数据简单示例讲解
2017/03/29 Javascript
JS实现动态给标签控件添加事件的方法示例
2017/05/13 Javascript
vue地区选择组件教程详解
2018/05/04 Javascript
nodejs前端模板引擎swig入门详解
2018/05/15 NodeJs
Vue动态获取width的方法
2018/08/22 Javascript
Vue.js路由实现选项卡简单实例
2019/07/24 Javascript
JQuery中DOM节点的操作与访问方法实例分析
2019/12/23 jQuery
[04:44]DOTA2西游记战队视频彩蛋流出 师徒开黑巧遇林书豪
2016/08/03 DOTA
[03:12]完美世界DOTA2联赛PWL DAY7集锦
2020/11/06 DOTA
轻松理解Python 中的 descriptor
2017/09/15 Python
VSCode下配置python调试运行环境的方法
2018/04/06 Python
matplotlib.pyplot绘图显示控制方法
2019/01/15 Python
python使用requests模块实现爬取电影天堂最新电影信息
2019/04/03 Python
Python常用编译器原理及特点解析
2020/03/23 Python
Python爬虫抓取指定网页图片代码实例
2020/07/24 Python
耐克中国官方商城:Nike中国
2018/10/18 全球购物
Omio俄罗斯:一次搜索公共汽车、火车和飞机的机票
2018/11/17 全球购物
Sarenza德国:法国最大的时尚鞋和包包网上商店
2019/06/08 全球购物
解释一下ruby中的特殊方法与特殊类
2013/02/26 面试题
气象学专业个人求职信
2014/04/22 职场文书
小学少先队辅导员述职报告
2015/01/10 职场文书
财务会计岗位职责
2015/02/03 职场文书
win11系统中dhcp服务异常什么意思? Win11 DHCP服务异常修复方法
2022/04/08 数码科技
速龙x4-860k处理器相当于i几
2022/04/20 数码科技