javascript實(shí)現(xiàn)網(wǎng)頁(yè)背景煙花效果的方法
本文實(shí)例講述了javascript實(shí)現(xiàn)網(wǎng)頁(yè)背景煙花效果的方法。分享給大家供大家參考。具體如下:
這里的網(wǎng)頁(yè)背景煙花爆炸特效,不用說(shuō)是用Js實(shí)現(xiàn)的,配合黑色背景效果最好,五顏六色的煙花效果,四散的煙花效果,以前發(fā)過(guò)一些網(wǎng)頁(yè)上的煙花特效,本款類似,但代碼更簡(jiǎn)潔。
運(yùn)行效果如下圖所示:

具體代碼如下:
<html>
<head>
<title>背景的煙花效果</title>
<style type="text/css">
<!--
body {
background-color: #000000;
}
-->
</style></head>
<body>
<script language="JavaScript">
var col = new Array('#ffffff','#fff000','#ffa000','#ff00ff','#00ff00','#0000ff','#ff0000');
var p='<div id="rearDiv" style="position:absolute;top:0px;left:0px">';
var n=0;
for (i=0;i<14;++i){
n++;
if (n=(col.length-1)) n=0;
p=p+'<div style="position:relative;width:1px;height:1px;background:'+col[n]+';font-size:3px">.</div>';
}
p=p+"</div>";
document.write(p);
var Clrs = new Array('ff0000','00ff00','000aff','ff00ff','ffa500','ffff00','00ff00','ffffff','fffff0');
var sClrs = new Array('ffa500','55ff66','AC9DFC','fff000','fffff0');
var peepY;
var peepX;
var step = 5;
var tallyStep = 0;
var backColor = 'ffa000';
var Mtop = 250;
var Mleft = 250;
function dissilient() {
peepY = window.document.body.clientHeight/3;
peepX = window.document.body.clientWidth/8;
enlarge();
tallyStep+= step;
reduce();
T=setTimeout("dissilient()",20);
}
function enlarge(){
for ( i = 0 ; i < rearDiv.all.length ; i++ ) {
var c=Math.round(Math.random()*(Clrs.length-1));
if (tallyStep < 90)
rearDiv.all[i].style.background=backColor;
if (tallyStep > 90)
rearDiv.all[i].style.background=Clrs[c];
rearDiv.all[i].style.top = Mtop + peepY*Math.sin((tallyStep+i*5)/3)*Math.sin(550+tallyStep/100);
rearDiv.all[i].style.left = Mleft + peepY*Math.cos((tallyStep+i*5)/3)*Math.sin(550+tallyStep/100);
}
}
function reduce(){
if (tallyStep == 220) {
tallyStep = -10;
var k=Math.round(Math.random()*(sClrs.length-1));
backColor = sClrs[k];
Dtop = window.document.body.clientHeight - 250;
Dleft = peepX * 3.5;
Mtop = Math.round(Math.random()*Dtop);
Mleft = Math.round(Math.random()*Dleft);
document.all.rearDiv.style.top = Mtop+document.body.scrollTop;
document.all.rearDiv.style.left = Mleft+document.body.scrollLeft;
if ((Mtop < 20) || (Mleft < 20)) {
Mtop += 90;
Mleft += 90;
}
}
}
dissilient();
</script>
</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à)效果
- JS基于面向?qū)ο髮?shí)現(xiàn)的放煙花效果
- 原生Js實(shí)現(xiàn)簡(jiǎn)易煙花爆炸效果的方法
- JS煙花背景效果實(shí)現(xiàn)方法
- JS實(shí)現(xiàn)超炫網(wǎng)頁(yè)煙花動(dòng)畫(huà)效果的方法
- js實(shí)現(xiàn)炫酷的煙花效果
相關(guān)文章
分享一個(gè)自己寫(xiě)的簡(jiǎn)單的javascript分頁(yè)組件
這篇文章主要分享一個(gè)自己寫(xiě)的簡(jiǎn)單的javascript分頁(yè)組件,效果十分不錯(cuò),代碼也很詳盡,這里推薦給小伙伴們。2015-02-02
基于ajax與msmq技術(shù)的消息推送功能實(shí)現(xiàn)代碼
這篇文章主要介紹了基于ajax與msmq技術(shù)的消息推送功能實(shí)現(xiàn)代碼,具有一定的參考價(jià)值,有興趣的可以了解一下。2016-12-12
JS 實(shí)現(xiàn)導(dǎo)航欄懸停效果(續(xù)2)
發(fā)現(xiàn)原來(lái)的方法還有是有幾個(gè)問(wèn)題:首先Js代碼冗余,導(dǎo)航條上的Tab是用js實(shí)現(xiàn)跳轉(zhuǎn)而不是超鏈接,還有導(dǎo)航條本身用fixed定位,但沒(méi)有被設(shè)置為水平居中,而是在JS中更改left值使其居中2013-09-09
JavaScript多種濾鏡算法實(shí)現(xiàn)代碼實(shí)例
這篇文章主要介紹了JavaScript多種濾鏡算法實(shí)現(xiàn)代碼實(shí)例,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下2019-12-12
跨域?yàn)g覽器設(shè)置解決前端跨域問(wèn)題
這篇文章主要為大家介紹了前端跨域?yàn)g覽器設(shè)置解決前端跨域問(wèn)題的方法,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2022-07-07
ajax分頁(yè)效果(bootstrap模態(tài)框)
這篇文章主要為大家詳細(xì)介紹了ajax分頁(yè)效果的實(shí)現(xiàn)方法,結(jié)合bootstrap模態(tài)框使用 ,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-01-01

