You are on page 1of 1

// // // // // //

Bubbles Javascript copyright 23rd February 2006, by Stephen Chapman permission to use this Javascript on your web page is granted provided that all of the code in this script (including these comments) is used without any alteration you can change the number of bubbles if you like

var num_bubbles = 15; var bubbles = ["http:\/\/z.about.com\/d\/javascript\/1\/0\/0\/1\/bubble.gif"]; // window size tests function findLivePageWidth() {return window.innerWidth != null? window.innerWidt h: document.body != null? document.body.clientWidth:700;}function findLivePageHe ight() {return window.innerHeight != null? window.innerHeight: document.body != null? document.body.clientHeight:500;} function posX() {return typeof window.pageXOffset != 'undefined' ? window.pageXO ffset:document.documentElement.scrollLeft? document.documentElement.scrollLeft:d ocument.body.scrollLeft? document.body.scrollLeft:0;} function posY() {return typeof window.pageYOffset != 'undefined' ? window.pageYO ffset:document.documentElement.scrollTop? document.documentElement.scrollTop: do cument.body.scrollTop?document.body.scrollTop:0;} // make bubbles var speed = 50;var movw = new Array();var move = new Array();var stepw = new Arr ay();var posw = new Array();var posh = new Array();var dir = new Array();var win Width;var winHeight; function setSize() {winWidth = findLivePageWidth()-50;winHeight = findLivePageHe ight()-50;} function startBubbles() {setSize(); var content = ''; for (var i = 0; i < num_bu bbles; i++){move[i] = 0;movw[i] = 11+ Math.random()*4;posw[i] = Math.random()*(w inWidth-35)+12;posh[i] = Math.random()*winHeight;stepw[i] = 0.02 + Math.random() /10;dir[i] = (Math.random()>0.5)?1:-1;content += '<div id="bub'+ i +'" style="po sition: absolute; z-index: '+ i +'; visibility:hidden;" onclick="posh['+i+']=-50 ;"><img src="'+bubbles[Math.floor(Math.random()*bubbles.length)]+ '" border="0"> </div>';} document.getElementById('bubble').innerHTML = content;setTimeout("more Bubbles()", speed);} function moreBubbles() {for (var i = 0; i < num_bubbles; i++) {if (posh[i] < 0) {posw[i] = 10+ Math.random()*(winWidth-movw[i]-30);posh[i] = winHeight;dir[i]=(M ath.random()<0.5)?1:-1;stepw[i] = 0.02 + Math.random()/9;} move[i] += stepw[i] * dir[i]; posh[i]-=1; if (Math.abs(move[i]) > 3) {dir[i]=-dir[i];posw[i]+=movw[i] *move[i]; move[i]=0;} objstyle = document.getElementById('bub'+i).style; objstyl e.left = posX()+posw[i] + movw[i]*move[i]; objstyle.top = posY()+posh[i] - 1;obj style.visibility = 'visible';} setTimeout("moreBubbles()", speed);} window.onload = startBubbles; window.onresize = setSize;

You might also like