基于JavaScript實(shí)現(xiàn)彈幕特效
本文實(shí)例為大家分享了js實(shí)現(xiàn)彈幕特效的具體代碼,供大家參考,具體內(nèi)容如下
此處使用HBuilder編譯,最簡(jiǎn)單的彈幕效果,希望各位前輩不吝指教。
注意用的是jquery-2.0.3.js
<!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <title></title> </head> <style type="text/css"> *{ padding: 0; margin: 0; } .shooter{ width: 600px; height: 60px; /*background: black;*/ margin: 0 auto; } .shooter input{ width: 300px; height: 40px; border: none; border-radius: 7px; box-shadow: 0 0 8px rgba(182,195,214,0.6)inset; padding-left: 15px; margin-top: 10px; } .shooter button{ width: 80px; height: 40px; border: none; margin-left: 10px; background-color:#339B53; border-radius:8px; color: white; cursor: pointer; } .shooter button:hover{ font-size: 14px; background:#008000; } .content{ width: 100%; height: 600px; background: gray; position: relative; overflow: hidden; } .bullet{ position: absolute; /*right: 0;*/ /*left:1600px;*/ word-break: keep-all; /*不讓單詞折行*/ } </style> <body> <div class="shooter"> <input type="text"/> <button>發(fā)射</button> </div> <div class="content"> </div> <script type="text/javascript" src="js/jquery-2.0.3.js" ></script> <script type="text/javascript"> $("button").click(function(){ var msg = $("input").val(); //取出輸入框內(nèi)容 if(msg.length > 15){ alert("字?jǐn)?shù)不得超過15個(gè)!"); return; } var bullet = $("<div>"); //生成一條彈幕 bullet.text(msg); //將輸入框內(nèi)容放置到div中 bullet.addClass("bullet"); //為bullet這個(gè)div添加樣式bullet bullet.css("top",Math.round(Math.random()*500)); //隨機(jī)設(shè)置彈幕位置 bullet.css("left","1600px"); bullet.css("font-size",Math.round(Math.random()*60)+12+"px"); bullet.css("color","rgb("+Math.round(Math.random()*255)+","+Math.round(Math.random()*255)+","+Math.round(Math.random()*255)+")"); // alert(window.getComputedStyle(bullet,null).width); bullet.animate({ left:-1000//此處視為bug,應(yīng)該隨著彈幕的長(zhǎng)短而變化 },Math.round(Math.random()*9000)+1000,"linear", function(){ bullet.remove(); //當(dāng)運(yùn)動(dòng)結(jié)束時(shí),刪除彈幕 }); $(".content").append(bullet); //將彈幕添加到屏幕中 }); </script> </body> </html>
下面是展示的彈幕效果(顯示的白線在谷歌瀏覽器中是看不出來的,在錄制時(shí)會(huì)看出來,此處又一bug):
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
- 簡(jiǎn)單實(shí)現(xiàn)JavaScript彈幕效果
- JS實(shí)現(xiàn)的視頻彈幕效果示例
- JavaScript直播評(píng)論發(fā)彈幕切圖功能點(diǎn)集合效果代碼
- 一篇文章教你學(xué)會(huì)js實(shí)現(xiàn)彈幕效果
- javascript實(shí)現(xiàn)視頻彈幕效果(兩個(gè)版本)
- javascript實(shí)現(xiàn)彈幕墻效果
- js實(shí)現(xiàn)簡(jiǎn)易彈幕系統(tǒng)
- 原生js實(shí)現(xiàn)彈幕效果
- JS實(shí)現(xiàn)視頻彈幕效果
- JS實(shí)現(xiàn)彈幕小案例
相關(guān)文章
一篇文章弄懂javascript中的執(zhí)行棧與執(zhí)行上下文
這篇文章主要給大家介紹了關(guān)于javascript中執(zhí)行棧與執(zhí)行上下文的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家學(xué)習(xí)或者使用javascript具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面來一起學(xué)習(xí)學(xué)習(xí)吧2019-08-08小程序中實(shí)現(xiàn)自定義頭部導(dǎo)航組件的詳細(xì)過程
這篇文章主要介紹了小程序中實(shí)現(xiàn)自定義頭部導(dǎo)航組件的詳細(xì)過程,本文通過實(shí)例代碼給大家介紹的非常詳細(xì),感興趣的朋友跟隨小編一起看看吧2024-06-06JavaScript躲避行星游戲?qū)崿F(xiàn)全程
本文將使用 canvas 創(chuàng)建一個(gè)躲避小行星游戲。另外將重點(diǎn)介紹的兩個(gè)方面是:如何使用 JavaScript 來檢測(cè)鍵盤輸入,以及如何在游戲中使用和處理 HTML5 音頻。希望你能夠喜歡2022-08-08JavaScript常用工具函數(shù)匯總(瀏覽器環(huán)境)
這篇文章主要匯總了JavaScript常用的工具函數(shù),幫助大家更好的理解和使用JavaScript,感興趣的朋友可以了解下2020-09-09js拖動(dòng)滑塊和點(diǎn)擊水波紋效果實(shí)例代碼
在本文里面我們給大家分享了js實(shí)現(xiàn)拖動(dòng)滑塊和點(diǎn)擊水波紋效果的相關(guān)實(shí)例代碼,有需要的朋友們學(xué)習(xí)下。2018-10-10javascript使用location.search的示例
本文介紹javascript 使用location.search獲取當(dāng)前地址欄參數(shù)的實(shí)例2013-11-11