Automatically changing background images

Automatically changing background images
0

#1

Hi guys,

Working on the random quote generator and I’m trying to have my background images change. I have been googling and cannot find a good solution to this. I currently have a script that “seemingly” is transitioning through images, but is not displaying the images. Could anyone take a look/help me out? Would be greatly appreciated!

This is the JS:

 var images = ["bjj2.jpg", "bjj3.jpg"];
$(function () {
    var i = 0;
    $("#dvImage").css("background-image", "url(images/" + images[i] + ")");
    setInterval(function () {
        i++;
        if (i == images.length) {
            i = 0;
        }
        $("#dvImage").fadeOut("slow", function () {
            $(this).css("background-image", "url(images/" + images[i] + ")");
            $(this).fadeIn("slow");
        });
    }, 1000);
});

#2

Hey! You forgot to put you images in the folder “images”. Although in the code the path is images/… Do that and it’ll work.


#3

You’re the best! Thanks so much!

Only issue is that now I don’t know how to make the whole page the image. It (obviously) is limiting it to the div. Any solution for that?