原生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" class="texts" 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í)有所幫助,也希望大家多多支持腳本之家。
- 簡(jiǎn)單實(shí)現(xiàn)JavaScript彈幕效果
- 基于JavaScript實(shí)現(xiàn)彈幕特效
- JS實(shí)現(xiàn)的視頻彈幕效果示例
- JavaScript直播評(píng)論發(fā)彈幕切圖功能點(diǎn)集合效果代碼
- 一篇文章教你學(xué)會(huì)js實(shí)現(xiàn)彈幕效果
- javascript實(shí)現(xiàn)視頻彈幕效果(兩個(gè)版本)
- javascript實(shí)現(xiàn)彈幕墻效果
- js實(shí)現(xiàn)簡(jiǎn)易彈幕系統(tǒng)
- JS實(shí)現(xiàn)視頻彈幕效果
- JS實(shí)現(xiàn)彈幕小案例
相關(guān)文章
js實(shí)例入門(簡(jiǎn)單展開或關(guān)閉)
簡(jiǎn)直的展開或關(guān)閉2008-11-11
AngularJs+Bootstrap實(shí)現(xiàn)漂亮的計(jì)算器
這篇文章主要為大家詳細(xì)介紹了angularJs+Bootstrap實(shí)現(xiàn)漂亮的計(jì)算器,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-08-08
用javascript判斷IE版本號(hào)簡(jiǎn)單實(shí)用且向后兼容
項(xiàng)目中需要判斷IE版本號(hào),又因?yàn)?jQuery 2.0 去除了對(duì)瀏覽器版本號(hào)的判斷于是就看到一老外寫的一段代碼,下面與大家分享下2013-09-09
JavaScript實(shí)戰(zhàn)之帶收放動(dòng)畫效果的導(dǎo)航菜單
這篇文章主要為大家詳細(xì)介紹了JavaScript實(shí)戰(zhàn)之帶收放動(dòng)畫效果的導(dǎo)航菜單,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2016-08-08
layui點(diǎn)擊左側(cè)導(dǎo)航欄,實(shí)現(xiàn)不刷新整個(gè)頁(yè)面,只刷新局部的方法
今天小編就為大家分享一篇layui點(diǎn)擊左側(cè)導(dǎo)航欄,實(shí)現(xiàn)不刷新整個(gè)頁(yè)面,只刷新局部的方法,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來(lái)看看吧2019-09-09
基于JavaScript實(shí)現(xiàn)評(píng)論框展開和隱藏功能
本文通過實(shí)例代碼給大家介紹了基于JavaScript實(shí)現(xiàn)評(píng)論框展開和隱藏功能,感興趣的朋友參考下吧2017-08-08
js+css3實(shí)現(xiàn)旋轉(zhuǎn)效果
本文主要介紹了js+css3實(shí)現(xiàn)旋轉(zhuǎn)效果的方法。具有一定的參考價(jià)值,下面跟著小編一起來(lái)看下吧2017-01-01

