原生js實現(xiàn)彈幕效果
更新時間:2020年11月29日 09:33:31 作者:Mr.王征
這篇文章主要為大家詳細介紹了原生js實現(xiàn)彈幕效果,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
本文實例為大家分享了js實現(xiàn)彈幕效果的具體代碼,供大家參考,具體內(nèi)容如下
效果展示:
源碼展示:
<!doctype html> <html> <head> <meta charset="utf-8"> <title>原生js實現(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"> 感: 最近貢獻一下我在教學中的小案例 希望能給你一些幫助 ,希望大家繼續(xù)關注我的博客 --王 </pre> </body> </html>
以上就是本文的全部內(nèi)容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。
相關文章
AngularJs+Bootstrap實現(xiàn)漂亮的計算器
這篇文章主要為大家詳細介紹了angularJs+Bootstrap實現(xiàn)漂亮的計算器,具有一定的參考價值,感興趣的小伙伴們可以參考一下2017-08-08JavaScript實戰(zhàn)之帶收放動畫效果的導航菜單
這篇文章主要為大家詳細介紹了JavaScript實戰(zhàn)之帶收放動畫效果的導航菜單,具有一定的參考價值,感興趣的小伙伴們可以參考一下2016-08-08layui點擊左側導航欄,實現(xiàn)不刷新整個頁面,只刷新局部的方法
今天小編就為大家分享一篇layui點擊左側導航欄,實現(xiàn)不刷新整個頁面,只刷新局部的方法,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2019-09-09基于JavaScript實現(xiàn)評論框展開和隱藏功能
本文通過實例代碼給大家介紹了基于JavaScript實現(xiàn)評論框展開和隱藏功能,感興趣的朋友參考下吧2017-08-08