views:

24

answers:

1

I've seen a lot of different background switching based upon link classes, however I just want a simple background switcher on any page load (no cookies) and not link dependent.

is there a simple method for this? jquery?

+1  A: 

Are looking for javascript timers?

Example:

setInterval("switchBackground()", 1000);

function switchBackground( )
{
   $("body").css("backgroundImage", "xxx");
}

I hope this help!

Edit:

To generate random background at start:

$(document).ready(function() {
   //This will be random from bg1.jpg to bg10.jpg
   $("body").css("backgroundImage", "/images/bg"+GenerateNumber(10)+".jpg");

   //1 to max
   function GenerateNumber(max) {
      return Math.floor(Math.random()*max) + 1;
   }
});
Mouhannad
This is exactly how I would do it, maybe store the instance of the interval to allow it to be cancelled. (+1)
Byron Cobb
this is right on track - however, I don't think I need intervals. I just want a random body background to load when a page loads.
Jason
Ahh i misunderstood your question. I hope the new edit is better!
Mouhannad
great thanks @Mouhannad - also, if I add a class to this for the image (for 100% background fill) will it create any issues?
Jason
Ok, i tried adding class="background-full" to the image, and then adding a body class to the css - body.background-full {width: 100%; position: absolute; top: 0; left: 0;
Jason
but the image did not show - thoughts?
Jason