Good night everyone, I have a small challenge here and until now I have not been able to get the relief, if anyone could help me, I would be very grateful:
I'm trying to put 2 gifs in the same place on the page, like this:
loop {
1- page loads
2- Load gif1
3-delay 6000ms
4- remove gif1
5- Load gif2
6-delay 6000ms
7- remove gif2
}
That way in an eternal loop.
I managed to put the 2 banners to disappear and appear, the problem is that fade out, the gif keeps changing the frames, so when it fades in, it is in the middle of some frame, and it stays there out of sync ...
I searched here and it looks like I would have to remove the src attribute from the img tag, but I do not know how to put this in my function ...
Follow my code:
$( window ).load(function() {
var $elem = $('#bannertoppage .bannerp'), l = $elem.length, i = 0;
function go() {
$elem.eq(i % l).fadeIn(100, function() {
$elem.eq(i % l).fadeOut(100, function(){
go();
});
i++;
}).delay(6200)
}
go();
});
Thanks in advance!
(resolved) For those who need it, here is the final code:
html:
<div class="gif-wrapper">
<div id="0" class="gif-container">
<img class="gif-change" src="https://upload-assets.vice.com/files/2015/12/31/1451587321dj.gif"></div><divid="1" class="gif-container">
<img class="gif-change" src=''>
</div>
</div>
Jquery:
var gifs = [{src:'http://seusite.com.br/seugif1.gif', delay: 6000}, {src: 'http://seusite.com.br/seugif2.gif', delay: 6000}];
var totalGifs = gifs.length;
var gifShow = 0;
$('.gif-wrapper .gif-container:gt(0)').hide();
setTimeout(change_gif, gifs[gifShow].delay, gifShow);
function change_gif(gifShow) {
$('.gif-wrapper .gif-container').hide();
gifShow++;
if(gifShow == totalGifs) gifShow = 0;
$('.gif-wrapper #' +gifShow+ ' img.gif-change').prop('src', gifs[gifShow].src+ '?'+ new Date().getTime());
setTimeout(change_gif, gifs[gifShow].delay, gifShow);
$('.gif-wrapper #' +gifShow).show();
}
And the jigsaw of @Miguel link
ABCD!