Update link within a variable

1

I have the following code:

// Vegas
// $(".bg-fixed").vegas({
//     slides: [
//         { src: "/img/fundos/slide1.jpg" },
//         { src: "/img/fundos/slide2.jpg" },
//         { src: "/img/fundos/slide3.jpg" }
//     ],
//      overlay: '/js/vegas/overlays/03.png'
// });


//$(".bg-fixed").vegas();

var height = $(window).height();
var width = $(window).width();
var fundo = '';
//var x = 0;

function setBackground() {
    d = new Date();
    data1 = d.getTime();
    fundo = 'https://unsplash.it/g/' + width + '/' + height + '?random?' + data1;

    console.log(fundo)

    var slides = $(".bg-fixed").vegas('options', 'slides');
  slides.push({src:fundo});

    //$(".bg-fixed").vegas('options', 'transition', 'slideLeft2').vegas('next');

    $(".bg-fixed")
    .vegas('options', 'slides', slides)
    .vegas('options', 'transition', 'slideDown')
    .vegas('options', 'overlay', '/js/vegas/overlays/03.png')
    .vegas('jump',    slides.length - 1)
    .vegas('options', 'transition', 'slideLeft2');

    delete fundo;

}

setBackground();

setInterval(setBackground, 10000);

The goal is to get a new link image every ten seconds.

But the image is always the same ...
I can not clean the varable background with a new value. If you need the complete code or the site link I can send.

    
asked by anonymous 05.07.2016 / 20:50

1 answer

1

In order for the image to be different, you need to pass a parameter that varies to the URL being used - otherwise the browser cache will assume that the image you are looking for is the same (since URL has not changed) and will use the local version (cache).

You have the right idea, but there is a problem with the implementation: To separate the query parameters from the URL you should use & , not ? . If you change the line

fundo = 'https://unsplash.it/g/' + width + '/' + height + '?random?' + data1;

by

fundo = 'https://unsplash.it/g/' + width + '/' + height + '?random&_=' + data1;

You should receive a different picture with each call.

    
05.07.2016 / 21:21