原生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>
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持好吧啦網(wǎng)。
相關(guān)文章:
1. asp(vbs)Rs.Open和Conn.Execute的詳解和區(qū)別及&H0001的說明2. PHP設(shè)計(jì)模式中工廠模式深入詳解3. CSS hack用法案例詳解4. ThinkPHP5實(shí)現(xiàn)JWT Token認(rèn)證的過程(親測(cè)可用)5. 用css截取字符的幾種方法詳解(css排版隱藏溢出文本)6. asp中response.write("中文")或者js中文亂碼問題7. JSP數(shù)據(jù)交互實(shí)現(xiàn)過程解析8. PHP session反序列化漏洞超詳細(xì)講解9. ASP 信息提示函數(shù)并作返回或者轉(zhuǎn)向10. ASP+ajax實(shí)現(xiàn)頂一下、踩一下同支持與反對(duì)的實(shí)現(xiàn)代碼
