Smike,
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<title> - jsFiddle demo</title>
<style type='text/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;
background: no-repeat center center;
}
#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;
}
</style>
<script>
window.onload = function() {
(function() {
var container = document.getElementById("container"),
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 = sliderRules.length - 1;
function slideMove() {
i += this.id == "next" ? 1 : -1;
if (i === array.length) {
i = 0;
}
if (i < 0) {
i = (array.length - 1);
}
sliderRules[i].click()
}
if (document.addEventListener) {
button.addEventListener("click", slideMove, false);
previous.addEventListener("click", slideMove, false);
}
for (; j > -1; j--) {
var sliderRule = sliderRules[j];
sliderRule.indx = j; // dataset
sliderRule.addEventListener("click", setImage, false);
}
sliderRule.click();
function setImage(e) {
e = e || window.event;
var link = this.href;
container.style.backgroundImage = "url(" + link + ")";
old && old.classList.remove("active");
old = this;
i = +this.indx;
old.classList.add("active");
e.preventDefault();
}
}());
}
</script>
</head>
<body>
<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>
</body>
</html>
|