原生js實(shí)現(xiàn)彈幕效果
本文實(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' value='這是一個(gè)彈幕。。。'><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)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持好吧啦網(wǎng)。
相關(guān)文章:
1. python web框架的總結(jié)2. 以PHP代碼為實(shí)例詳解RabbitMQ消息隊(duì)列中間件的6種模式3. Python如何進(jìn)行時(shí)間處理4. python使用ctypes庫調(diào)用DLL動(dòng)態(tài)鏈接庫5. 詳解Python模塊化編程與裝飾器6. Python基于pyjnius庫實(shí)現(xiàn)訪問java類7. Python使用shutil模塊實(shí)現(xiàn)文件拷貝8. Python實(shí)現(xiàn)迪杰斯特拉算法過程解析9. html小技巧之td,div標(biāo)簽里內(nèi)容不換行10. python裝飾器三種裝飾模式的簡單分析
