Script Categories













Background Effects >>> Star Field (Only IE and OP).

Appears as if you are flying through a star field in space.

Add the below code to the <body> section of your page:

<style type="text/css">
.star {
position:absolute;
layer-background-color:white;
visibility:visible;
top:-50px;
width:50px;
height:50px;
font-size:1px;
background-color:white;
}
</style>

<script language="javascript" type="text/javascript">
/* Visit http://www.yaldex.com/ for full source code
and get more free JavaScript, CSS and DHTML scripts! */
<!-- Begin
if (document.all)
{
document.bgColor='black';
var starnum = 75; // Number of stars
var _all = 'all.';
var _style = '.style';
var xoffset, yoffset, w_x, w_y, tmpx, tmpy, scrlx, scrly;
function getstartpos(obj) {
obj.deltay = Math.floor(Math.random() * 12);
obj.deltax = Math.floor(Math.random() * 12);
obj.xdir = (Math.floor(Math.random() * 2) == 1) ? '+' : '-';
obj.ydir = (Math.floor(Math.random() * 2) == 1) ? '+' : '-';
obj.counter = 1;
obj.width = 1;
obj.height = 1;
obj
.pixelTop = yoffset+document.body.scrollTop;
obj.pixelLeft = xoffset+document.body.scrollLeft;
}
function movestar(starN) {
tmpx = starN.deltax*starN.counter+starN.counter;
tmpy = starN.deltay*starN.counter+starN.counter;
starN.width = starN.counter/3;
starN.height = starN.counter/3;
scrlx = document.body.scrollLeft;
scrly = document.body.scrollTop;
if ((starN.pixelLeft+tmpx >= w_x+scrlx)||(starN.pixelTop+tmpy >= w_y+scrly) || (starN.pixelLeft-tmpx <= scrlx)||(starN.pixelTop-tmpy <= scrly)) {
getstartpos(starN);
}
else {
eval('starN.pixelTop'+starN.ydir+'=tmpy');
eval('starN.pixelLeft'+starN.xdir+'=tmpx');
   }
starN.counter++;
}
function animate() {
for(i=1; i <= starnum; i++) {
movestar(eval('star'+i));
}
setTimeout('animate()', 100);
}
function findwindowparams() {
w_x =  document.body.clientWidth;
w_y =  document.body.clientHeight;
xoffset = w_x / 2;
yoffset = w_y / 2;
for (i = 1; i <= starnum; i++) {
getstartpos(eval('star'+i));
   }
}

window.onresize = findwindowparams;
window.onload = new Function("findwindowparams(); animate();");

for (i = 1; i <= starnum; i++) {
document.writeln('<div id="star'+i+'" class="star"></div>');
eval('var star'+i+'=document.'+_all+'star'+i+_style);
}
}

// End -->
</script>

Get Advanced
JavaScript and Ajax Editor,
Validator and Debugger!

1st JavaScript Editor.



Code was highlighted by 1st JavaScript Editor (The Best JavaScript Editor!).




©