29Jul/090
Have fancy exploding stars on your website
->
Here is how you can have fancy exploding stars on your website.
Put the code below within your site's source code. If you dont know how to implement this code into your site, please goto how to implement the code to your website
Code:
<!-- this script is from www.manycodes.com --> <script LANGUAGE="JavaScript1.2"> <!-- //set Interval between each firework display, var intervals=2000 var sparksOn = true; var speed = 25; var power = 1; //Dont change these values------- var documentWidth=documentHeight=randomx=randomy=leftcorner=topcorner=0 var ns=(document.layers); var ie=(document.all); var sparksAflyin = false; var allDivs = new Array(10); var totalSparks = 0; //------------------------------- function initAll(){ if(!ns && !ie){ sparksOn = false; return; } setInterval("firework()",intervals) if (ns) document.captureEvents(Event.MOUSEDOWN | Event.MOUSEMOVE); for(dNum=0; dNum<7; ++dNum){ if(ie) allDivs[dNum]=eval('document.all.sDiv'+dNum+'.style'); else allDivs[dNum]=eval('document.layers["sDiv'+dNum+'"]'); } } function firework(){ //below code detects the browser dimenions if (ie){ documentWidth=document.body.clientWidth documentHeight=document.body.clientHeight leftcorner=document.body.scrollLeft topcorner=document.body.scrollTop } else if (ns){ documentWidth=window.innerWidth documentHeight=window.innerHeight leftcorner=pageXOffset topcorner=pageYOffset } //below code randomly generates a set of coordinates that fall within the dimension randomx=leftcorner+Math.floor(Math.random()*documentWidth) randomy=topcorner+Math.floor(Math.random()*documentHeight) if(sparksOn){ if(!sparksAflyin){ sparksAflyin=true; totalSparks=0; for(var spark=0;spark<=6;spark++){ dx=Math.round(Math.random()*50); dy=Math.round(Math.random()*50); moveTo(spark,randomx,randomy,dx,dy); } } } } function moveTo(i,tempx,tempy,dx,dy){ if(ie){ if(tempy+80>(document.body.offsetHeight+document.body.scrollTop)) tempy=document.body.offsetHeight+document.body.scrollTop-80; if(tempx+80>(document.body.offsetWidth+document.body.scrollLeft)) tempx=document.body.offsetWidth+document.body.scrollLeft-80; } if(tempx>-50&&tempy>-50){ tempx+=dx;tempy+=dy; allDivs[i].left=tempx; allDivs[i].top=tempy; dx-=power;dy-=power; setTimeout("moveTo("+i+","+tempx+","+tempy+","+dx+","+dy+")",speed) } else ++totalSparks if(totalSparks==7){ sparksAflyin=false; totalSparks=0; } } window.onload=initAll //End--> </script> <style> #sDiv0 {position:absolute; height:1; width:1; font-family:arial black; font-size:25px; color:Aqua;} #sDiv1 {position:absolute; height:1; width:1; font-family:arial black; font-size:22px; color:red;} #sDiv2 {position:absolute; height:1; width:1; font-family:arial black; font-size:20px; color:blue;} #sDiv3 {position:absolute; height:1; width:1; font-family:arial black; font-size:15px; color:orange;} #sDiv4 {position:absolute; height:1; width:1; font-family:arial black; font-size:25px; color:yellow;} #sDiv5 {position:absolute; height:1; width:1; font-family:arial black; font-size:25px; color:lightgreen;} #sDiv6 {position:absolute; height:1; width:1; font-family:arial black; font-size:20px; color:silver;} </style> <p></p> <div id="sDiv0"> *</div> <div id="sDiv1"> *</div> <div id="sDiv2"> *</div> <div id="sDiv3"> *</div> <div id="sDiv4"> *</div> <div id="sDiv5"> *</div> <div id="sDiv6"> *</div><font face="Tahoma"><a target="_blank" href="http://www.manycodes.com/category/java/javascript-codes/"><span style="font-size: 8pt; text-decoration: none">JavaScript Free Code</span></a></font>
22Jul/090
How to make stars moving in background of your website
->
Here is how you can make stars moving in background of your website. Make your website the sky and have lots and lots of stars showing on it.
Put the code below within your site's <head> </head> tags. If you dont know how to implement this code into your site, please goto how to implement the code to your website
Code:
<pre><!-- this script is from www.manycodes.com --></pre> <body> <!-- STEP ONE: Insert the onLoad event handler into your BODY tag --> <BODY BGCOLOR="#000000" onLoad="fly()"> <!-- STEP TWO: Paste this code into the BODY of your HTML document --> <SCRIPT LANGUAGE="JavaScript"> <!-- Begin SmallStars = 30; LargeStars = 10; SmallYpos = new Array(); SmallXpos = new Array(); LargeYpos = new Array(); LargeXpos = new Array(); Smallspeed= new Array(); Largespeed= new Array(); ns=(document.layers)?1:0; if (ns) { for (i = 0; i < SmallStars; i++) { document.write("<LAYER NAME='sn"+i+"' LEFT=0 TOP=0 BGCOLOR='#FFFFF0' CLIP='0,0,1,1'></LAYER>"); } for (i = 0; i < LargeStars; i++) { document.write("<LAYER NAME='ln"+i+"' LEFT=0 TOP=0 BGCOLOR='#FFFFFF' CLIP='0,0,2,2'></LAYER>"); } } else { document.write('<div style="position:absolute;top:0px;left:0px">'); document.write('<div style="position:relative">'); for (i = 0; i < SmallStars; i++) { document.write('<div id="si" style="position:absolute;top:0;left:0;width:1px;height:1px;background:#fffff0;font-size:1px"></div>'); } document.write('</div>'); document.write('</div>'); document.write('<div style="position:absolute;top:0px;left:0px">'); document.write('<div style="position:relative">'); for (i = 0; i < LargeStars; i++) { document.write('<div id="li" style="position:absolute;top:0;left:0;width:2px;height:2px;background:#ffffff;font-size:2px"></div>'); } document.write('</div>'); document.write('</div>'); } WinHeight = (document.layers)?window.innerHeight:window.document.body.clientHeight; WinWidth = (document.layers)?window.innerWidth:window.document.body.clientWidth; for (i = 0; i < SmallStars; i++) { SmallYpos[i] = Math.round(Math.random() * WinHeight); SmallXpos[i] = Math.round(Math.random() * WinWidth); Smallspeed[i]= Math.random() * 5 + 1; } for (i = 0; i < LargeStars; i++) { LargeYpos[i] = Math.round(Math.random() * WinHeight); LargeXpos[i] = Math.round(Math.random() * WinWidth); Largespeed[i] = Math.random() * 10 + 5; } function fly() { var WinHeight = (document.layers)?window.innerHeight:window.document.body.clientHeight; var WinWidth = (document.layers)?window.innerWidth:window.document.body.clientWidth; var hscrll = (document.layers)?window.pageYOffset:document.body.scrollTop; var wscrll = (document.layers)?window.pageXOffset:document.body.scrollLeft; for (i = 0; i < LargeStars; i++) { LargeXpos[i] -= Largespeed[i]; if (LargeXpos[i] < -10) { LargeXpos[i] = WinWidth; LargeYpos[i] = Math.round(Math.random() * WinHeight); Largespeed[i] = Math.random() * 10 + 5; } if (ns) { document.layers['ln'+i].left = LargeXpos[i]; document.layers['ln'+i].top = LargeYpos[i] + hscrll; } else { li[i].style.pixelLeft = LargeXpos[i]; li[i].style.pixelTop = LargeYpos[i] + hscrll; } } for (i = 0; i < SmallStars; i++) { SmallXpos[i] -= Smallspeed[i]; if (SmallXpos[i] < -10) { SmallXpos[i] = WinWidth; SmallYpos[i] = Math.round(Math.random()*WinHeight); Smallspeed[i] = Math.random() * 5 + 1; } if (ns) { document.layers['sn'+i].left = SmallXpos[i]; document.layers['sn'+i].top = SmallYpos[i]+hscrll; } else { si[i].style.pixelLeft = SmallXpos[i]; si[i].style.pixelTop = SmallYpos[i]+hscrll; } } setTimeout('fly()', 10); } // End --> </script> <!-- Script Size: 3.79 KB --> <pre><font face="Tahoma"><a target="_blank" href="http://www.manycodes.com/"><span style="font-size: 8pt; text-decoration: none">JavaScript Free Code</span></a></font></pre>