I was wondering if anyone could help me out, or point me in the right direction. I'm looking for a snippet of jquery that will automatically change the background image of a div every say 5 seconds or so. My initial bg image is set in css, but i'm not sure how to create the function to make it swap between an array of images?
I have 5 images:
bg-1.jpg, bg-2.jpg, bg-3.jpg, bg-4.jpg, bg-5.jpg.
Currently my div is set to bg-1.jpg.
<div id="page_bg"></div>
Don't really have any code to show, but hopefully someone can help me out :)
If those are the actual image names, you really wouldn't need an Array.
In the
return (str % 5) + 1;
part, the number5
represents the total number of images. They should be sequentially indexed starting with1
like yours are.EDIT: Or if there will be a number elsewhere in the URL, then do this instead:
Something like this should do the trick?