What am I doing now?
Random & Slideshow Background 
Friday, October 19, 2007, 03:19 PM - Scripts
Posted by Administrator
First add a style for the background to get the image where you want it on the page, like:


<style>
body {
background:center 200px no-repeat fixed;
}
</style>


Then add this code anywhere (in a .js file, on the page, whatever, it will work from anywhere)

var bG= {
addEvent: function(obj,evt, fn) {if (obj.addEventListener) {obj.addEventListener(evt, fn, false);
} else if (obj.attachEvent) {obj.attachEvent('on'+evt, fn);} else {obj['on'+evt]=fn;}},
params:function() {bG.bI=arguments;},
init:function() {
var bod=document.getElementsByTagName("body");
if (bG.bI[0]==1) {
// Random Background
var j=parseInt(Math.random()*(bG.bI.length-1));j=(isNaN(j))?1:j++;
bod[0].style.backgroundImage="url("+bG.bI[j]+")";
} else {
// Slideshow Background
bod[0].style.backgroundImage="url("+bG.bI[bG.ss]+")";
bG.ss++;
if (bG.ss==bG.bI.length)bG.ss=2;
setTimeout("bG.init()",bG.bI[1])
}
},
bI:[],ss:2
}


Finally, add the following two lines of code (again, anywhere works) - the first line has a few arguments to it:
the first on is 1 or 2, 1 for random background and 2 for slideshow
For random background, the rest are the URLs to the images for the backgrounds
For slideshows, the next one is the millisecond delay to replace the background, then the rest of the image URLs to cycle through.


bG.params(2,5000,"/images/slideshowEB.jpg","/images/slideshowEC.jpg","/images/slideshowEI.jpg","/images/slideshowIDG.jpg");
bG.addEvent(window, "load", bG.init, false);

add comment ( 2 views )   |  0 trackbacks   |  permalink   |   ( 2.9 / 424 )

<<First <Back | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | Next> Last>>