Как зациклить слайдер на нативном js
Подскажите, пожалуйста, что нужно прописать в условии, чтобы при достижении последней картинки, устанавливалась 1-ая. На данный момент происходит просто остановка.
const arrowRight = () => {
if (display > bannerStore.getBanners().length - 1)
return document
.getElementById('banner' + display)
.setAttribute('style', 'margin-left: -100%');
display++;
renderDots(bannerStore.getBanners(), display);
showButton();
};
Ответы (1 шт):
Автор решения: Air
→ Ссылка
let index = 0;
setInterval(() => {
if (index <= 4) {
console.clear();
console.log(index);
index++;
} else {
index = 0;
}
}, 1000)
const arrowRight = () => {
if (display > bannerStore.getBanners().length - 1) {
return
document
.getElementById('banner' + display)
.setAttribute('style', 'margin-left: -100%');
display++;
renderDots(bannerStore.getBanners(), display);
showButton();
} else {
display = 1;
}
};