How do I change background-image of the site dynamically? [closed]

0

So, I wanted to make a bg-image change dynamically the same in this example: link

The background changes every 5 seconds.

Does anyone know how?

    
asked by anonymous 23.03.2017 / 01:58

1 answer

2

You can do it via JavaScript with a timer running every 5 sec. See example:

// initial call, or just call refresh directly
setInterval(AsyncTrocaImg, 5000);


function AsyncTrocaImg() {
    $.post(base + "Home/GetNewImg", {}, function (URL) {
         $('body').css('background-image', 'url('+URL+')');
    }).fail(function () {
        console.log("error");
    })
}

But be careful with the images, so that your site does not get "heavy".

It would also have some other forms even simple, but this is the way I would do it.

See also if these links help you:

CSS various backgrounds

Change background of a class dynamically

    
23.03.2017 / 02:29