原生js實(shí)現(xiàn)彈幕效果
更新時間:2020年11月29日 09:33:31 作者:Mr.王征
這篇文章主要為大家詳細(xì)介紹了原生js實(shí)現(xiàn)彈幕效果,文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下
本文實(shí)例為大家分享了js實(shí)現(xiàn)彈幕效果的具體代碼,供大家參考,具體內(nèi)容如下
效果展示:
源碼展示:
<!doctype html> <html> <head> <meta charset="utf-8"> <title>原生js實(shí)現(xiàn)彈幕效果</title> <style> * { padding:0; margin:0; } .all { width:600px; height:400px; background:#000000; } /*.danmu {*/ /*width:600px;*/ /*height:500px;*/ /*background:#000000;*/ /*overflow:hidden;*/ /*z-index:50;*/ /*}*/ </style> </head> <body> <div class="all"> </div> <input type="text" class="texts" value="這是一個彈幕。。。"> <button>發(fā)送</button> <script> var all = document.querySelector('.all'); var danmu = document.querySelector('.danmu'); var buttons = document.querySelector('button'); var texts = document.querySelector('.texts'); console.log(texts.value); buttons.onclick = function() { var p = document.createElement('p'); p.style.position = 'absolute'; p.innerHTML = texts.value; p.style.left = 600 + 'px'; p.style.color = 'white'; p.style.zIndex = 100; p.style.top = Math.random() * 490 + 'px'; all.appendChild(p); var x = setInterval(function() { p.style.left = parseInt(p.style.left) - 10 + 'px'; if ((parseInt(p.style.left) + 600) <= 0) { all.removeChild(p); clearInterval(x); } }, 100) } </script> <pre style="color:red"> 感: 最近貢獻(xiàn)一下我在教學(xué)中的小案例 希望能給你一些幫助 ,希望大家繼續(xù)關(guān)注我的博客 --王 </pre> </body> </html>
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
AngularJs+Bootstrap實(shí)現(xiàn)漂亮的計算器
這篇文章主要為大家詳細(xì)介紹了angularJs+Bootstrap實(shí)現(xiàn)漂亮的計算器,具有一定的參考價值,感興趣的小伙伴們可以參考一下2017-08-08用javascript判斷IE版本號簡單實(shí)用且向后兼容
項(xiàng)目中需要判斷IE版本號,又因?yàn)?jQuery 2.0 去除了對瀏覽器版本號的判斷于是就看到一老外寫的一段代碼,下面與大家分享下2013-09-09JavaScript實(shí)戰(zhàn)之帶收放動畫效果的導(dǎo)航菜單
這篇文章主要為大家詳細(xì)介紹了JavaScript實(shí)戰(zhàn)之帶收放動畫效果的導(dǎo)航菜單,具有一定的參考價值,感興趣的小伙伴們可以參考一下2016-08-08layui點(diǎn)擊左側(cè)導(dǎo)航欄,實(shí)現(xiàn)不刷新整個頁面,只刷新局部的方法
今天小編就為大家分享一篇layui點(diǎn)擊左側(cè)導(dǎo)航欄,實(shí)現(xiàn)不刷新整個頁面,只刷新局部的方法,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2019-09-09基于JavaScript實(shí)現(xiàn)評論框展開和隱藏功能
本文通過實(shí)例代碼給大家介紹了基于JavaScript實(shí)現(xiàn)評論框展開和隱藏功能,感興趣的朋友參考下吧2017-08-08js+css3實(shí)現(xiàn)旋轉(zhuǎn)效果
本文主要介紹了js+css3實(shí)現(xiàn)旋轉(zhuǎn)效果的方法。具有一定的參考價值,下面跟著小編一起來看下吧2017-01-01