又一枚精彩的弹幕效果jQuery实现
简易弹幕效果:将发布的内容随机显示在弹幕右侧,逐渐左移最后消失。
涉及知识点:val()、random()、height()、css()、append()、remove()等,主要是元素的操作
html代码:
1
2
3
4
5
6
7
8
9
|
< a href = "#" >弹幕技术</ a > < div class = "mask" > < a href = "#" class = "button" >X</ a > </ div > <!-- 底部发言框前端 --> < div class = "bottom" > < input class = "content" ></ input > < a href = "#" class = "send" >发表言论</ a > </ div > |
css代码:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
|
html,body{ background-image : url ( "images/208.jpg" ); height : 100% ;//文字的显示区域要设置好 } div.mask{ position : fixed ; width : 100% ; height : 100% ; background-color : black ; opacity: 0.5 ; top : 0px ; left : 0px ; } div. bottom { width : 100% ; height : 77px ; background-color : #090909 ; position : fixed ; bottom : 0px ; left : 0px ; text-align : center ; line-height : 77px ; } div. bottom input.content{ width : 605px ; height : 37px ; border : none ; border-radius: 10px 0px 0px 10px ; font-size : 16px ; font-family : 'Microsoft Yahei' ; } div. bottom a.send{ background-color : green ; color : #fff ; display :inline- block ; width : 150px ; height : 40px ; 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 : 50px ; height : 50px ; border-radius: 30px ; background-color : #660000 ; color : #fff ; position : fixed ; top : 20px ; right : 20px ; text-align : center ; line-height : 50px ; font-size : 30px ; 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 ; } |
jQuery代码:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
|
$( 'a.send' ).click( function (){ //获取内容,创建新元素,并设置位置追加到目标元素中 var val=$( 'input.content' ).val(); var $content=$( '<div class="text">' +val+ '</div>' ); var top=Math.random()*$(document.body).height()-77; $content.css( 'top' ,top); $( 'div.mask' ).append($content); //移动到最右侧,直接删除该元素 $content.animate({right:$(document.body).width()+100},8000, function (){ $( this ).remove(); }); }); $( 'div.button' ).click( function (){ $( 'div.mask' ).hide(2000); }); |
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持脚本之家。
又一枚精彩的弹幕效果jQuery实现的更多相关文章
- h5做直播的弹幕效果
最近在搞弹幕效果所以就写一个关于弹幕的吧,刚开始寻思去网上找插件的,但找的插件和我的需求都不太相符,其实做弹幕我知道的有两种方法: 1:一种是用canvas和对象来完成弹幕想过,用canvas来完成弹 ...
- JQ实现弹幕效果
JQ实现弹幕效果,快来吐糟你的想法吧 效果图: 代码如下,复制即可使用: <!DOCTYPE html> <html> <head> <meta charse ...
- marquee标签弹幕效果
播放个视频的时候看到很有趣的弹幕,想着前端能不能做个弹幕效果.弹幕是滚动的,所以首先想到了<marquee>标签.但事实上,<marquee>标签不是w3c的标准,只是主流的浏 ...
- DIV的摇晃效果---jquery实现
DIV的摇晃效果---jquery实现 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" &quo ...
- 点击弹出 +1放大效果 -- jQuery插件
20140110更新: <!doctype html> <html> <head> <meta charset="UTF-8"> & ...
- android 弹幕效果demo
记得之前有位朋友在我的公众号里问过我,像直播的那种弹幕功能该如何实现?如今直播行业确实是非常火爆啊,大大小小的公司都要涉足一下直播的领域,用斗鱼的话来讲,现在就是千播之战.而弹幕则无疑是直播功能当中最 ...
- CSS3展现精彩的动画效果 css3的动画属性
热火朝天的css3无疑吸引了很多前端开发者的眼球,然而在css3中的动画属性则是新功能中的主打招牌,说到css3的动画属性不得不让人想起这三个属性:Transform﹑Transition﹑Anima ...
- Android 自定义View修炼-自定义弹幕效果View
一.概述 现在有个很流行的效果就是弹幕效果,满屏幕的文字从右到左飘来飘去.看的眼花缭乱,看起来还蛮cool的 现在就是来实现这一的一个效果,大部分的都是从右向左移动漂移,本文的效果中也支持从左向右的漂 ...
- Android:简单的弹幕效果达到
首先,效果图.分类似至360检测到的骚扰电话页面: 布局非常easy,上面是一个RelativeLayout,以下一个Button. 功能: (1)弹幕生成后自己主动从右側往左側滚动(Translat ...
随机推荐
- php类中的魔术方法
1.构造函数 析构函数class pt{ function __construct($data) { echo "pt is start ..."; $this->pr($d ...
- (哈夫曼树)HuffmanTree的java实现
参考自:http://blog.csdn.net/jdhanhua/article/details/6621026 哈夫曼树 哈夫曼树(霍夫曼树)又称为最优树. 1.路径和路径长度在一棵树中,从一个结 ...
- [转]ASP.NET Core--根据方案来限制身份
本文转自:http://www.cnblogs.com/duyao/p/5980105.html 翻译如下: 在某些情况下,比如单页的应用程序,可以与多种认证来方式结合.例如,您的应用程序可能使用基于 ...
- Ubuntu 一直掉线 以及连不上网 解决办法
新装了一个Ubuntu 系统16.04才使用的时候一切顺利 但是过了两三天 就会出现 频繁掉线的情况 于是上网找大神们的解决办法 把文件 /etc/ppp/options 里面的一个数值改大一点 l ...
- C#把 DataTable转换为Model实体
public static List<T> GetModelFromDB<T>( DataTable dt ) { List<T> data = new List& ...
- Android--sharepreference总结
SharedPreferences类,它是一个轻量级的存储类,特别适合用于保存软件配置参数. SharedPreferences保存数据,其背后是用xml文件存放数据,文件存放在/data/data/ ...
- bootstrap自学总结不间断更新
2.栅格系统 container-fluid 自适应宽度100% container 固定宽度(适应响应式) 屏幕宽度=x x>=1200 1170 992< ...
- React服务端渲染总结
欢迎吐槽 : ) 本demo地址( 前端库React+mobx+ReactRouter ):https://github.com/Penggggg/react-ssr.本文为笔者自学总结,有错误的地方 ...
- [LeetCode] Convex Polygon 凸多边形
Given a list of points that form a polygon when joined sequentially, find if this polygon is convex ...
- [LeetCode] Roman to Integer 罗马数字转化成整数
Given a roman numeral, convert it to an integer. Input is guaranteed to be within the range from 1 t ...