又一枚精彩的彈幕效果jQuery實(shí)現(xiàn)
簡易彈幕效果:將發(fā)布的內(nèi)容隨機(jī)顯示在彈幕右側(cè),逐漸左移最后消失。
涉及知識(shí)點(diǎn):val()、random()、height()、css()、append()、remove()等,主要是元素的操作
html代碼:
<a href="#">彈幕技術(shù)</a> <div class="mask"> <a href="#" class="button">X</a> </div> <!-- 底部發(fā)言框前端 --> <div class="bottom"> <input class="content"></input> <a href="#" class="send">發(fā)表言論</a> </div>
css代碼:
html,body{ background-image:url("images/208.jpg"); height:100%;//文字的顯示區(qū)域要設(shè)置好 } 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(){ //獲取內(nèi)容,創(chuàng)建新元素,并設(shè)置位置追加到目標(biāo)元素中 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); //移動(dòng)到最右側(cè),直接刪除該元素 $content.animate({right:$(document.body).width()+100},8000,function(){ $(this).remove(); }); }); $('div.button').click(function(){ $('div.mask').hide(2000); });
以上就是本文的全部內(nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
Jquery EasyUI Datagrid右鍵菜單實(shí)現(xiàn)方法
這篇文章主要為大家詳細(xì)介紹了Jquery EasyUI Datagrid右鍵菜單的實(shí)現(xiàn)方法,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2016-12-12jquery 注意事項(xiàng)與常用語法小結(jié)
jquery 注意事項(xiàng)與常用語法小結(jié),學(xué)習(xí)jquery的朋友最好收藏下。2010-06-06JQuery省市聯(lián)動(dòng)效果實(shí)現(xiàn)過程詳解
這篇文章主要介紹了JQuery省市聯(lián)動(dòng)效果實(shí)現(xiàn)過程詳解,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下2020-05-05基于jquery實(shí)現(xiàn)的自動(dòng)補(bǔ)全功能
這篇文章主要介紹了基于jquery實(shí)現(xiàn)的自動(dòng)補(bǔ)全功能的方法,涉及jQuery操作數(shù)據(jù)實(shí)現(xiàn)補(bǔ)全的技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下2015-03-03jquery插件開發(fā)之實(shí)現(xiàn)google+圈子選擇功能
最近項(xiàng)目中用到的一個(gè)效果,類似于Google+的添加圈子功能。本文插件約8成封裝,好多功能是依據(jù)項(xiàng)目中實(shí)際需求寫的。若要使用,可根據(jù)自身情況擴(kuò)展修改2014-03-03jQuery實(shí)現(xiàn)獲取綁定自定義事件元素的方法
這篇文章主要介紹了jQuery實(shí)現(xiàn)獲取綁定自定義事件元素的方法,涉及jQuery方法重載、事件綁定及元素操作的相關(guān)技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下2015-12-12jQuery結(jié)合CSS制作動(dòng)態(tài)的下拉菜單
這篇文章主要介紹了jQuery結(jié)合CSS制作一個(gè)動(dòng)態(tài)的下拉菜單,下拉菜單可以彌補(bǔ)空間的不足,感興趣的小伙伴們可以參考一下2015-10-10