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插件Echarts实现的渐变色柱状图
Mar 23 jQuery
jQuery实现简单漂亮的Nav导航菜单效果
Mar 29 jQuery
jquery处理checkbox(复选框)是否被选中实例代码
Jun 12 jQuery
jQuery回调方法使用示例
Jun 26 jQuery
基于jQuery Easyui实现登陆框界面
Jul 10 jQuery
jQuery中过滤器的基本用法示例
Oct 11 jQuery
利用jQuery+localStorage实现一个简易的计时器示例代码
Dec 25 jQuery
jQuery实现炫丽的3d旋转星空效果
Jul 04 jQuery
jQuery实现上下滚动公告栏详细代码
Nov 21 jQuery
jQuery实现图片随机切换、抽奖功能(实例代码)
Oct 23 jQuery
jQuery实现简易QQ聊天框
Feb 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
NO3第三帝国留言簿制作过程
2006/10/09 PHP
PHP中集成PayPal标准支付的实现方法分享
2012/02/06 PHP
php使用substr()和strpos()联合查找字符串中某一特定字符的方法
2015/05/12 PHP
Windows下PHP开发环境搭建教程(Apache+PHP+MySQL)
2016/06/13 PHP
php车辆违章查询数据示例
2016/10/14 PHP
thinkphp5.0整合phpsocketio完整攻略(绕坑)
2018/10/12 PHP
JQuery live函数
2010/12/24 Javascript
基于javascript的JSON格式页面展示美化方法
2014/07/02 Javascript
分享9个最好用的JavaScript开发工具和代码编辑器
2015/03/24 Javascript
javascript 正则表达式去空行方法
2017/01/24 Javascript
jQuery实现html table行Tr的复制、删除、计算功能
2017/07/10 jQuery
React中使用collections时key的重要性详解
2017/08/07 Javascript
vue中过滤器filter的讲解
2019/01/21 Javascript
nodejs微信开发之接入指南
2019/03/17 NodeJs
Python中处理unchecked未捕获异常实例
2015/01/17 Python
django从请求到响应的过程深入讲解
2018/08/01 Python
在Python中使用gRPC的方法示例
2018/08/08 Python
python 利用for循环 保存多个图像或者文件的实例
2018/11/09 Python
PyQt5显示GIF图片的方法
2019/06/17 Python
opencv调整图像亮度对比度的示例代码
2019/09/27 Python
pycharm 实现本地写代码,服务器运行的操作
2020/06/08 Python
CSS3 实现的火焰动画
2020/12/07 HTML / CSS
加拿大休闲和工业服装和鞋类零售商:L’Équipeur
2018/01/12 全球购物
美体小铺印度官网:The Body Shop印度
2019/10/17 全球购物
高三政治教学反思
2014/02/06 职场文书
大学班级干部的自我评价分享
2014/02/10 职场文书
早会主持词
2014/03/17 职场文书
走群众路线学习笔记
2014/11/06 职场文书
学雷锋日活动总结
2015/02/06 职场文书
2015年幼儿园保育员工作总结
2015/04/23 职场文书
活动经费申请报告
2015/05/15 职场文书
2015年女职工工作总结
2015/05/15 职场文书
使用pandas生成/读取csv文件的方法实例
2021/07/09 Python
Element实现动态表格的示例代码
2021/08/02 Javascript
Python循环之while无限迭代
2022/04/30 Python
MySQL数据库 任意ip连接方法
2022/05/20 MySQL