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 image of https://unsplash.it every ten seconds.
But the image is always the same...
I can’t clean the variable bottom with a new value.
If you need the complete code or the link of the site I can send.
I’m not sure why you’re using that parameter ? Random? + data1, because when testing this on the site, it always generates the same image, regardless of the value of the data1...
– Julyano Felipe
You can try to pass the timestamp (cache) separated by
&
, and not for a second?
, what may be causing the browser to ignore you - something likefundo = 'https://unsplash.it/g/' + width + '/' + height + '?random&_=' + data1
– carlosfigueira
You want the image to change every how long?
– Julyano Felipe
@Julyanofelipe ignore ? Random? is an unfortunate attempt to add a date at the end of the URL to "force" the refresh of the variable.
– sistematico
@Julyanofelipe I want to change every 10 seconds, but the problem is not the time itself, the problem is that the variable does not change. The image is always the same.
– sistematico
Test allocate the creation of the variable by placing it within the function
– Julyano Felipe
@carlosfigueira worked first, thank you very much friend, from heart.
– sistematico
Don’t forget to call the correct URL https://unsplash.it/width/height/? Random
– Julyano Felipe