简易弹幕效果:将发布的内容随机显示在弹幕右侧,逐渐左移最后消失。
涉及知识点:val()、random()、height()、css()、append()、remove()等,主要是元素的操作
html代码:
<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代码:
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代码:
$('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); });
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。
风云阁资源网 Design By www.bgabc.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
风云阁资源网 Design By www.bgabc.com
暂无评论...
更新日志
2024年09月20日
2024年09月20日
- 战锤40K星际战士2职业强度排行
- 交错战线PVE国家队成员以及常用角色推荐
- 交错战线角色养成攻略一览
- 群星《2024好听新歌27》AI调整音效【WAV分轨】
- 黑鸭子-《伴你二十年》11CD[WAV分轨]
- 魏新雨《为你祈祷+新歌精逊2CD[WAV]
- 影心、明萨拉你选哪个?国外美女COS《博德3》
- 澳洲女子骑车跌入“自杀树”丛 疼痛持续9个月崩溃
- 育碧公布2024“她创力”计划:为女性游戏人提供辅导
- 刘美君.2017-千色·30总选3CD【环球】【WAV+CUE】
- 群星.2022-星河长明电视原声带【乐有奇思】【FLAC分轨】
- 陈淑桦.1995-淑桦盛开Forever【滚石】【WAV+CUE】
- 《再来一张》评测:出师成败皆系“赌”
- 《银河汉堡店》测评:我是银河走菜王!
- 《末日地带2》评测:酣畅淋漓的“和面”之旅