原生Js實(shí)現(xiàn)簡(jiǎn)易煙花爆炸效果的方法
本文實(shí)例講述了原生Js實(shí)現(xiàn)簡(jiǎn)易煙花爆炸效果的方法。分享給大家供大家參考。具體分析如下:
實(shí)現(xiàn)原理: 在一定范圍內(nèi),隨機(jī)生成一些div,形成煙花效果
<html>
<head>
<meta charset="utf-8">
<title>js煙花效果</title>
<script type="text/javascript">
document.onclick=function (ev)
{
var oEvent=ev||event;
var aDiv=[];
var oDiv=null;
var _oDiv=document.createElement('div');
var i=0;
var x=oEvent.clientX;
var y=oEvent.clientY;
_oDiv.style.position='absolute';
_oDiv.style.background='red';
_oDiv.style.width='3px';
_oDiv.style.height='30px';
_oDiv.style.left=oEvent.clientX+'px';
_oDiv.style.top=document.documentElement.clientHeight+'px';
document.body.appendChild(_oDiv);
var t=setInterval(function (){
if(_oDiv.offsetTop<=y)
{
clearInterval(t);
show();
document.body.removeChild(_oDiv);
}
_oDiv.style.top=_oDiv.offsetTop-30+'px';
}, 30);
function show()
{
var oDiv=null;
for(i=0;i<100;i++)
{
oDiv=document.createElement('div');
oDiv.style.width='3px';
oDiv.style.height='3px';
oDiv.style.background='#'+Math.ceil(Math.random()*0xEFFFFF+0x0FFFFF).toString(16);
oDiv.style.position='absolute';
oDiv.style.left=x+'px';
oDiv.style.top=y+'px';
var a=Math.random()*360;
//oDiv.speedX=Math.random()*40-20;
//oDiv.speedY=Math.random()*40-20;
oDiv.speedX=Math.sin(a*180/Math.PI)*20*Math.random();
oDiv.speedY=Math.cos(a*180/Math.PI)*20*Math.random();
document.body.appendChild(oDiv);
aDiv.push(oDiv);
}
}
setInterval(doMove, 30);
function doMove()
{
for(i=0;i<aDiv.length;i++)
{
aDiv[i].style.left=aDiv[i].offsetLeft+aDiv[i].speedX+'px';
aDiv[i].style.top=aDiv[i].offsetTop+aDiv[i].speedY+'px';
aDiv[i].speedY+=1;
if(aDiv[i].offsetLeft<0 || aDiv[i].offsetLeft>document.documentElement.clientWidth || aDiv[i].offsetTop<0 || aDiv[i].offsetTop>document.documentElement.clientHeight)
{
document.body.removeChild(aDiv[i]);
aDiv.splice(i, 1);
}
}
}
};
</script>
</head>
<body style="overflow:hidden; background:black;">
</body>
</html>
希望本文所述對(duì)大家的javascript程序設(shè)計(jì)有所幫助。
- JavaScript實(shí)現(xiàn)煙花綻放動(dòng)畫(huà)效果
- 原生JS實(shí)現(xiàn)煙花效果
- JS實(shí)現(xiàn)放煙花效果
- JS實(shí)現(xiàn)煙花爆炸效果
- JS實(shí)現(xiàn)網(wǎng)頁(yè)煙花動(dòng)畫(huà)效果
- javascript實(shí)現(xiàn)網(wǎng)頁(yè)背景煙花效果的方法
- JS基于面向?qū)ο髮?shí)現(xiàn)的放煙花效果
- JS煙花背景效果實(shí)現(xiàn)方法
- JS實(shí)現(xiàn)超炫網(wǎng)頁(yè)煙花動(dòng)畫(huà)效果的方法
- js實(shí)現(xiàn)炫酷的煙花效果
相關(guān)文章
bootstrap表格內(nèi)容過(guò)長(zhǎng)時(shí)用省略號(hào)表示的解決方法
這篇文章主要介紹了bootstrap表格內(nèi)容過(guò)長(zhǎng)時(shí)用省略號(hào)表示的解決方法,需要的朋友可以參考下2017-11-11JavaScript動(dòng)態(tài)設(shè)置div的樣式的方法
這篇文章主要介紹了JavaScript動(dòng)態(tài)設(shè)置div的樣式的方法的相關(guān)資料,需要的朋友可以參考下2015-12-12簡(jiǎn)單實(shí)現(xiàn)JavaScript彈幕效果
這篇文章主要幫助大家簡(jiǎn)單實(shí)現(xiàn)JavaScript彈幕效果,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-05-05Bootstrap Table表格一直加載(load)不了數(shù)據(jù)的快速解決方法
bootstrap-table是一個(gè)基于Bootstrap風(fēng)格的強(qiáng)大的表格插件神器。接下來(lái)通過(guò)本文給大家介紹Bootstrap Table表格一直加載(load)不了數(shù)據(jù)的快速解決方法,感興趣的朋友一起看看吧2016-09-09