Reputation: 91
So I've been looking around for a way to rotate my background image, Probably every 7 or 8 seconds. The problem is that it seems to me unclear how I would go about using the javascript of php code. Would I put it under the tag or does it go in the body? Or do I upload it to my server? Sorry if this seems like a basic question, I am just a begginer.
Also what would be the best code to use? In your opinion.
Upvotes: 1
Views: 131
Reputation: 13496
Upload all your images in a folder on server each image with a number as file number
/Images/BG/...
Then use the following function to change the background of body
var currentImageIndex = 0;
var maxImageIndex = 10;
setTimeout(function()
{
currentImageIndex = currentImageIndex + 1;
if(currentImageIndex > maxImageIndex) currentImageIndex = 0;
$(body).css("background-image", "/Images/BG/" + currentImageIndex + ".JPG");
}, 7000);
remember to use 0's image as the background image by default (in CSS)
Upvotes: 3