无自动播放效果
css
<style>
*{
margin: 0;
padding: 0;
}
li{
list-style: none;
}
.box{
width: 600px;
height: 400px;
margin: 0 auto;
position: relative;
overflow: hidden;
}
ul{
float: left;
width: 600%;
height:400px;
}
ul>li{
float: left;
display: none;
}
ol{
position: absolute;
bottom:20px;
right: 50%;
transform: translateX(50%);
}
ol>li{
display: inline-block;
cursor: pointer;
width: 20px;
height: 20px;
border-radius: 50%;
background-color: rgba(44,44,44,.3);
border: 1px solid #fff;
}
#arrow_l,#arrow_r{
position: absolute;
cursor: pointer;
top: 50%;
transform: translateY(-50%);
z-index: 100;
width: 40px;
height: 70px;
background: url(./images/icon-slides.png);
border: none;
}
#arrow_l{
background-position-x: -86px;
}
#arrow_r{
right: 0;
background-position-x: -125px;
}
.current{
background-color: #ff4500;
}
</style>
html
<div class="box">
<button id="arrow_l"></button>
<button id="arrow_r"></button>
<ul>
<li style="display: block;"><img src="./images/01.png" alt=""></li>
<li><img src="./images/02.png" alt=""></li>
<li><img src="./images/03.png" alt=""></li>
<li><img src="./images/04.png" alt=""></li>
<li><img src="./images/05.png" alt=""></li>
</ul>
<ol class="circle">
<li class="current"></li>
<li></li>
<li></li>
<li></li>
<li></li>
</ol>
</div>
js
<script>
var list=document.querySelectorAll("ul>li");
var ol=document.querySelectorAll("ol>li");
var arrow_l=document.querySelector("#arrow_l");
var arrow_r=document.querySelector("#arrow_r");
var count=0;
function remove(){
for(var i=0;i<list.length;i++){
list[i].style.display="none";
}
for(var i=0;i<ol.length;i++){
ol[i].className="";
}
}
function add(){
remove();
list[count].style.display="block";
ol[count].className="cureent";
}
function towards(){
if(count==list.length-1){
count=0
}else{
count++;
}
add();
}
function aleft(){
if(count==0){
count=list.length-1;
}else{
count--;
}
add();
}
arrow_r.onclick=function(){
towards();
}
arrow_l.onclick=function(){
towards();
}
for(var i=0;i<ol.length;i++){
ol[i].setAttribute('index',i);
ol[i].onclick=function(){
aleft();
}
}
</script>