Jump to content

Change BG with centered IMG


kuran

Recommended Posts

hi... need some more help, I just can't get my head around javascript..I'm trying to have a row of links, that when pressed, load a centered (or tiled, if centered isn't possible) .jpg image as the background of that same site.Is this hard to do?Thanks in advance for any help!

Link to comment
Share on other sites

<html><head><title></title><script type="text/javascript">function changeBg(img){  var bodyObject = document.getElementsByTagName('body')[0];  bodyObject.style.backgroundImage = 'url(' + img + ')';  bodyObject.style.backgroundRepeat = 'no-repeat';  bodyObject.style.backgroundPosition = 'center';}</script></head><body><a href="javascript:changeBg('bgOne.jpg')">One</a><a href="javascript:changeBg('bgTwo.jpg')">Two</a><a href="javascript:changeBg('bgThree.jpg')">Three</a></body></html>

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...