原生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' 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ù)關(guān)注我的博客 --王</pre></body></html>
以上就是本文的全部內(nèi)容,希望對大家的學習有所幫助,也希望大家多多支持好吧啦網(wǎng)。
相關(guān)文章:
1. python GUI庫圖形界面開發(fā)之PyQt5動態(tài)(可拖動控件大小)布局控件QSplitter詳細使用方法與實例2. ASP將數(shù)字轉(zhuǎn)中文數(shù)字(大寫金額)的函數(shù)3. XML 非法字符(轉(zhuǎn)義字符)4. ASP 處理JSON數(shù)據(jù)的實現(xiàn)代碼5. js開發(fā)中的頁面、屏幕、瀏覽器的位置原理(高度寬度)說明講解(附圖)6. CSS清除浮動方法匯總7. 不要在HTML中濫用div8. vue跳轉(zhuǎn)頁面常用的幾種方法匯總9. CSS3實例分享之多重背景的實現(xiàn)(Multiple backgrounds)10. XML入門的常見問題(三)
