Jump to content

How to...build a site that shuffles bg color/css?


kuran

Recommended Posts

Hello,I'm building a very simple, straightforward single-page site. I want five different colors for the background of this site. What is the best way to 'shuffle' these colors randomly, so that whenever someone refreshes, or loads the site, he sees a different color?Is it possible to have multiple CSS files and shuffle them? Or should I be using Javascript?Any help would be greatly appreciated!

Link to comment
Share on other sites

Use javascript to generate the random number then use it's bgColor to set a colour

<html><head><script>var randomnumber=Math.floor(Math.ceil(Math.random()*5));if (randomnumber==1)document.bgColor="red";else if (randomnumber==2)document.bgColor="green";else if (randomnumber==3)document.bgColor="blue";else if (randomnumber==4)document.bgColor="yellow";else document.bgColor="purple";</script></head><body>Hello</body></html>

Link to comment
Share on other sites

Thanks for your quick help, I am not that great with HTML or JS...so I need some more assistance.If I simply paste your code in a empty html file, and try it, it doesn't work.. should I change something about the code first?

Link to comment
Share on other sites

No the code is fine, it's fully working.1. Copy everything from <html> to </html>2. Open new notepad and paste3. Save as random.htm4. Open up random.htm with your browser5. Hit refresh a couple of times to see the background colour changeThat's it.*note, if you are using IE 6 SP2 scripts are blocked, click the banner at the top of the screen and select "Allow Blocked Content..."*

Link to comment
Share on other sites

Odd, I am using a Mac and have tried multiple browsers (Safari, Firefox, ...) and it won't work. Java is enabled.Is there any other way to achieve what I want? Perhaps a index.html that randomly loads a page?I have tried Golive to paste the code, I hope that didn't cause the problem.Thanks,Wim

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...