JSFiddle - React, Tailwind, and code Playground
HTML
<div id="container">
<img src="https://www.gentec-eo.com/Content/images/home/slider/left-arrow.png" id="previous" width="40" height="40" >
<img src="https://www.gentec-eo.com/Content/images/home/slider/right-arrow.png" id="next" width="40" height="40" >
<ul class="nav">
<li><a class="rule" href="http://www.umnet.com/pic/diy/screensaver/3845b123-a01a.jpg"></a></li>
<li><a class="rule" href="http://www.iceis.pl/640x480/640x480_-_niagarafalls640x480.jpg"></a></li>
<li><a class="rule" href="http://www.umnet.com/pic/diy/screensaver/87832121-ea64.jpg"></a></li>
<li><a class="rule" href="http://www.blackberry-wallpapers.com/uploads/allimg/110514/2-1105142029510-L.jpg"></a></li>
</ul>
</div>
CSS
* {
margin: 0;
padding: 0;
}
ul {
list-style: none;
}
#container {
position: relative;
top: 20px;
width: 640px;
height: 480px;
margin: 0 auto;
box-shadow: 0 0 5px 5px rgba(0, 0, 0, .5);
transition: all .2s;
}
#previous {
position: absolute;
left: 10px;
top: 50%;
margin-top: -20px;
opacity: .5;
cursor: pointer;
}
#previous:hover, #next:hover {
opacity: 1;
}
#previous:active {
margin-top: -18px;
}
#next:active {
margin-top: -18px;
}
#next {
position: absolute;
right: 10px;
top: 50%;
margin-top: -20px;
opacity: .3;
cursor: pointer;
}
.nav {
position: absolute;
bottom: 0;
left: 50%;
width: 100px;
margin-left: -50px;
}
.nav li {
float: left;
margin-right: 5px;
margin-bottom: 5px;
}
.rule {
display: block;
height: 10px;
width: 10px;
border: 2px solid #fff;
border-radius: 50%;
}
.active {
background-color: red;
}
JavaScript
(function (){
var container = document.getElementById("container"),
containerBackground = container.style.background,
button = document.getElementById("next"),
previous = document.getElementById("previous"),
array = ["http://www.umnet.com/pic/diy/screensaver/3845b123-a01a.jpg", "http://www.iceis.pl/640x480/640x480_-_niagarafalls640x480.jpg", "http://www.umnet.com/pic/diy/screensaver/87832121-ea64.jpg", "http://www.blackberry-wallpapers.com/uploads/allimg/110514/2-1105142029510-L.jpg"],
sliderRules = document.querySelectorAll(".rule"),
old,
i = 0,
j;
container.style.background = "url(" + array[0] + ") no-repeat center center";
function slideNext(e) {
e = e || window.event;
i += 1;
if (i === array.length) {
i = 0;
}
container.style.background = "url(" + array[i] + ") no-repeat center center";
}
function slidePrevious(e) {
e = e || window.event;
i -= 1;
if (i < 0) {
i = (array.length - 1);
}
container.style.background = "url(" + array[i] + ") no-repeat center center";
}
if (document.addEventListener) {
button.addEventListener("click", slideNext, false);
previous.addEventListener("click", slidePrevious, false);
}
old = sliderRules[0];
old.classList.add("active");
for (j = 0; j < sliderRules.length; j += 1) {
var sliderRule = sliderRules[j];
sliderRule.addEventListener("click", setImage, false);
}
function setImage(e) {
e = e || window.event;
var link = this.href;
container.style.background = "url(" + link + ") no-repeat center center";
old.classList.remove("active");
old = this;
old.classList.add("active");
e.preventDefault();
}
}());