又一枚精彩的弹幕效果jQuery实现

简易弹幕效果:将发布的内容随机显示在弹幕右侧,逐渐左移最后消失。

涉及知识点:val()、random()、height()、css()、append()、remove()等,主要是元素的操作

HTML代码

rush:xhtml;">
ottom">

css代码

rush:css;"> 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代码

rush:js;"> $('a.send').click(function(){ //获取内容,创建新元素,并设置位置追加到目标元素中 var val=$('input.content').val(); var $content=$('
'); 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); });

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持编程之家。

相关文章

页面搜索关键词突出 // 页面搜索关键词突出 $(function () {...
jQuery实时显示日期、时间 html: <span id=&quot...
jQuery 添加水印 <script src="../../../.....
中文:Sys.WebForms.PageRequestManagerParserErrorExceptio...
1. 用Response.Write方法 代码如下: Response.Write(&q...
Jquery实现按钮点击遮罩加载,处理完后恢复 思路: 1.点击按...