View Full Version : randome background generator

10-02-2005, 12:22 AM
hi! i've been trying to look around, but I can't find any way to use CSS so that random background pictures appear every time the user enters my website

i guess one could also use javascript, but since i dont have much experience with that, i dont know how to get the background position always in the "top center" etc and other features of CSS

but, if some can help me out, give me a link to learn or some code in either javascript or CSS, i'd really appreciate it ...

thanks a lot!

10-02-2005, 05:45 AM
This script will work for 9 images named photo1.jpg through photo9.jpg, located in the same directory as the page this script is on.
<script type="text/javascript">
function random(n) {
return Math.floor((Math.random() % 1) * n);
document.documentElement.style.background="url('photo"+[random(9)+1]+".jpg') pink center no-repeat"
</script>As you can see by the part after the image declaration, it will accept conventional css values for background in the usual manner. Be aware, random means random so, the same image may be used twice or more times in a row.

10-02-2005, 11:38 AM
cool cool

works perfectly

thanks a lot!!!!