askkozy
12/31/2017 - 10:53 AM

simple-picture-slider.js

const prevButton = document.querySelector('#gallery .buttons .prev');
const nextButton = document.querySelector('#gallery .buttons .next');
const images = document.querySelectorAll('#gallery .photos img');  
let i = 0;


prevButton.onclick = function () {
    images[i].className = '';
    i -= 1;
    if (i < 0) {
      i = images.length - 1;
  }
   images[i].className = 'showed';   
  
} 
   

nextButton.onclick = function () {
    images[i].className = '';
    i += 1;
    if (i >= images.length) {
      i = 0;
  }
   images[i].className = 'showed';   
  
}