View Single Post
Old 09-17-2012, 05:37 PM   PM User | #6
krillezzz
New Coder

 
Join Date: Sep 2012
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
krillezzz is an unknown quantity at this point
Quote:
Originally Posted by LearningCoder View Post
Maybe changing the function to something like this:
Code:
var currentImgNumber = 1;
var numberOfImages = 3;

function switchImage(){
   currentImgNumber++;
   document.body.style.background = 'url(images/AdvertImage' + currentImgNumber + '.jpg)';
   if(currentImgNumber == numberOfImages){
       currentImgNumber = 0;
   }
}
Set your additional attributes for the image just like you would do in the css like no repeats x+y etc. You can just add to that statement your other declarations.

Regards,

LC.
Thanks for all your tips, I've been modifying my code into this:

Code:
var currentIndex = 1;
var totalIndex = 3;

function switchImage() 
{
	currentIndex++;
	document.content.style.background = 'url(images/kontor-' + currentIndex + '.png)';
	if (currentIndex == totalIndex) 
	{
		currentIndex = 1;
	}
}

function windowOnload() 
{
	setInterval("switchImage()", 3000);
}
My CSS look like this:

Code:
.content
{
	height: 600px;
	width: auto;
	padding: 0px;
	background-image: url("images/kontor-1.png");
	background-repeat: no-repeat;
	background-position: center;
}
And i run windowOnload() in
Code:
<body onload="windowOnload()">
,
the problem is what i think in the line:
Code:
document.content.style.background = 'url(images/kontor-' + currentIndex + '.png)';
I'm not sure that this make me change this url in the class content in my CSS, because it's still not working
krillezzz is offline   Reply With Quote