Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Jun 2011
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Radom background issues

    Hello I'm trying to do java for random background image for every time a page load. The problem is it ALWAYS goes to one image and that's it. Here's what I have:

    Code:
    <script type="text/javascript">
    function randomize(min, max) {
    	if (!min)
    		min = 0;
    	if (!max)
    		max = 1;
    	return Math.floor(Math.random()*(max+1)+min);
    }
    function randomBg() {
    	var bgs = new Array();
    	// I took these images from a site with a similar script already only to get example images
    	// I wrote this script myself
    	bgs.push("cheetah.jpg");
    	bgs.push("giraffe.jpg");
    	bgs.push("leopard.gif");
    	document.body.style.backgroundImage = "url(" + bgs[randomize(0, bgs.length-1)] + ")";
    }
    </script>
    <body onLoad="randomBg()" style="text-align:center;">
    Evertime it loads it will load what ever image is last listed. How do I make it change every time it loads?

  • #2
    New to the CF scene
    Join Date
    Jun 2011
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Arg it was the max setting

    if (!max)
    max = 1;

    I changed it to 3 and we're good now.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •