JSFiddle - React, Tailwind, and code Playground

by benhowdle89

HTML

<ul id="slider">
    <li>
        <img src="http://placekitten.com/400/300" />
    </li>
    <li>
        <img src="http://lorempixel.com/400/300" />
    </li>
    <li>
        <img src="http://placehold.it/400x300" />
    </li>
</ul>

CSS

* {
    border: 0;
    margin: 0;
    padding: 0;    
}

ul {
    position: relative;
    overflow: hidden;
    width: 400px;
    height: 300px;
}
li {
    list-style-type: none;
    position: absolute;
    top: 0;
    left: 0;
    transition: all 0.7s linear;
    -webkit-transition: all 0.7s linear;
    -moz-transition: all 0.7s linear;
    -o-transition: all 0.7s linear;
    -ms-transition: all 0.7s linear;
}
.moveRight {
    left: 400px;
}
.reset {
    left: 0;
}

JavaScript

var slider = document.getElementById('slider');
var sChildren = slider.children;
var sL = sChildren.length;
var currentIndex = 0;

DOMTokenList.prototype.removeMany = function (classes) {
    var array = classes.split(' ');
    for (var i = 0, length = array.length; i < length; i++) {
        this.remove(array[i]);
    }
}

for (i = 0; i < sL; i++) {
    //if (i == 0) continue;
    //sChildren[i].style.display = 'none'; 
}

setInterval(function () {
    if (currentIndex == (sL - 1)) currentIndex = 0;
    for(var i = 0; i < sChildren.length; i++){
        sChildren[i].classList.removeMany('reset moveRight');
    }
    var next = ((currentIndex + 1) > (sL - 1)) ? (sL - 1) : (currentIndex + 1);

    sChildren[next].classList.add('reset');
    
    sChildren[currentIndex].classList.add('moveRight');
    currentIndex++;
}, 2000);