Click to See Complete Forum and Search --> : Background image changes randomly at certain time
Perfidus
07-16-2008, 11:43 AM
As I already said in my small title...
I have an image in my site that I would like to change every (let's say minute) for a different one between 3 options without reloading the whole website (this is a pest for screen readers) is it possible?
Any hints?
gil davis
07-16-2008, 12:04 PM
<html>
<head>
<title>Change BG Image</title>
<style type="text/css">
body {
background: url("pic0.gif");
}
</style>
<script type="text/javascript">
var which = 0;
var ary = new Array();
ary[0] = new Image();
ary[0].src = "pic0.gif";
ary[1] = new Image();
ary[1].src = "pic1.gif";
ary[2] = new Image();
ary[2].src = "pic2.gif";
function doChange() {
which = (which + 1) % 3;
document.getElementsByTagName("body")[0].style.background = "url(" + ary[which].src + ")";
}
function changeBG() {
setInterval("doChange()", 1000*60); // one minute
}
</script>
</head>
<body onload="changeBG()">
</body>
</html>
Perfidus
07-16-2008, 12:26 PM
That worked like a charm, thank's a lot !!!!