Jump to content

Chaning Background using style.background


Bendude14

Recommended Posts

I am trying to change my background using style.background i have managed this ok but what i am now trying to implement is a fade effect between images.

 

I have the following code but its fading the wrong way and then does not fade my new image is just swaps it. I am sure there will be an easier way to do this if someone can help.

 

 

<script type="text/javascript">

window.onload = slideShow;


var i = 1;
var numOfImages = 3;

	function slideShow()
	{	
		//fade out the image
		setTimeout('initFade();', 1000);

			while(i <= numOfImages)
			{

				//call timeout again to keep going
				setTimeout('changeImage(i);', 5000);

				if(numOfImages == i)
				{
					i = 1;
				}
				else
				{
					i += 1;
				}
				break;

			}

	}


	function changeImage(img)
	{


		//then swap them over
	document.getElementById("HeaderMid").style.background = "url('images/Header"+img+".jpg') no-repeat center center";
	document.getElementById("Header").style.background = "url('images/Header"+img+".png')";




		slideShow();
	}


function initFade() {
var opacity = 0.9;
for (var k=10;k>0;k--)
{	
	setTimeout('setOpacity('+k+')',200*k);

}	
return false;
}

function setOpacity(value)
{

document.getElementById("HeaderMid").style.opacity  = value/10;

//document.getElementById("Header").style.filter = 'alpha(opacity=' + value*10 + ')';
}

</script>

 

Thanks

Ben

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.