PDA

View Full Version : randome background generator



lakp
10-02-2005, 01: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!
laksh

jscheuer1
10-02-2005, 06: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.

lakp
10-02-2005, 12:38 PM
cool cool

works perfectly

thanks a lot!!!!