Hello, I have a js that makes a list of images move forward and backward based on a variable, it progresses perfectly, however to return it randomly. Can someone help me solve it? the code is below:
var imgs = [
'produtos/Slide92.png',
'produtos/Slide93.png',
'produtos/Slide94.png',
];
var num_imgs = 1;
var next_three = num_imgs;
var prev_three = 0;
var next_imgs, prev_imgs;
for(var i = 0; i < next_three; i++) {
$('#galery').append('<img class="imgDinamica" src="' +imgs[i]+ '">');
}
$('#next').on('click', function() {
next_imgs = imgs.slice(next_three, next_three + num_imgs);
if(next_imgs.length === 0) {
next_three = 0;
next_imgs = imgs.slice(next_three, next_three + num_imgs);
}
$('.imgDinamica').each(function() {
if(typeof next_imgs[$(this).index()] === 'undefined') {
$(this).hide();
return true; // continue
}
$(this).show();
$(this).prop('src', next_imgs[$(this).index()]);
});
next_three += num_imgs;
});
$('#prev').on('click', function() {
prev_imgs = imgs.slice(prev_three - num_imgs, prev_three);
console.log(prev_three);
if(prev_imgs.length <= 0) {
prev_three = imgs.length;
prev_imgs = imgs.slice(prev_three - num_imgs, prev_three);
}
$('.imgDinamica').each(function() {
if(typeof prev_imgs[$(this).index()] === 'undefined') {
$(this).hide();
return true; // continue
}
$(this).show();
$(this).prop('src', prev_imgs[$(this).index()]);
});
prev_three -= num_imgs;
});
The original code is this: link