<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<style>
*{
padding: 0;
margin: 0;
}
ol,ul{
list-style: none;
}
.text{
width: 400px;
height: 400px;
margin: 50px auto;
overflow: hidden;
position: relative;
}
ul{
width: 400px;
height: 400px;
overflow: hidden;
position: relative;
}
ul li{
width: 400px;
height: 400px;
position: absolute;
opacity: 0;
}
.show{
opacity: 1;
z-index: 1;
}
img{
width: 100%;
height: 100%;
}
.btn1{
position: absolute;
top:45%;
left: 0;
z-index: 2;
font-size: 30px;
background-color: aqua;
opacity: 0.5;
cursor: pointer;
}
.btn2{
position: absolute;
top:45%;
right: 0;
z-index: 2;
font-size: 30px;
background-color: aqua;
opacity: 0.5;
cursor: pointer;
}
ol{
width: 200px;
height: 50px;
top: 90%;
left: 30%;
position: absolute;
z-index: 2;
}
ol li{
width: 20px;
height: 20px;
background-color: hotpink;
float: left;
border-radius: 50%;
text-align: center;
line-height: 20px;
margin-right: 10px;
opacity: 0.8;
cursor: pointer;
}
.active{
background-color: aquamarine;
}
</style>
</head>
<body>
<div class="text">
<ul>
<li class="show"><img src="img/img1.jpg"/></li>
<li><img src="img/img2.jpg" /></li>
<li><img src="img/img3.jpg"/></li>
<li><img src="img/img4.jpg"/></li>
<li><img src="img/img5.jpg"/></li>
</ul>
<span class="btn1"><</span>
<span class="btn2">></span>
<ol>
<li class="active">1</li>
<li>2</li>
<li>3</li>
<li>4</li>
<li>5</li>
</ol>
</div>
<script>
var img=document.querySelectorAll('ul li')
var li=document.querySelectorAll('ol li')
var span=document.querySelectorAll('span')
var ul=document.querySelector('ul')
var index=0
span[0].οnclick=function(){
if(index==-1){
index=img.length-1
}
for(let i=0;i<img.length;i++){
img[i].className=''
li[i].className=''
}
img[index].className='show'
li[index].className='active'
index--
}
span[1].οnclick=function(){
if(index==img.length){
index=0
}
for(let i=0;i<img.length;i++){
img[i].className=''
li[i].className=''
}
img[index].className='show'
li[index].className='active'
index++
}
for(let i=0;i<li.length;i++){
li[i].οnclick=function(){
index=i
for(let j=0;j<li.length;j++){
li[j].className=''
img[j].className=''
}
li[i].className='active'
img[i].className='show'
}
}
var timer=null
function autoPic(){
timer=setInterval(function(){
if(index==img.length){
index=0
}
for(let i=0;i<img.length;i++){
img[i].className=''
li[i].className=''
}
img[index].className='show'
li[index].className='active'
index++
},1000)
}
autoPic()
ul.parentNode.οnmοuseοver=function(){
clearInterval(timer)
}
ul.parentNode.onmouseout = ()=>{
autoPic()
}
</script>
</body>
</html>