<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>sliderShow</title>
<style>
.container{
position: relative;
width: 1240px;
margin:0 auto;
}
#pt>img:not(:first-child){
position: absolute;
top: 0;opacity: 0;
}
span{
width: 13px;height: 13px;
border-radius: 50%;
background-color: rgba(255,255,255,0);
border:1px solid #fff;
margin-right: 10px;
display: inline-block;
}
span:first-child{
background-color: rgba(255,255,255,1);
}
#sliderCicle{
position: absolute;
top: 450px;left: 620px;
z-index: 1;
}
#prev{
width: 30px;height: 60px;
position: absolute;top: 40%;
}
#next{
width: 30px;height: 60px;
position: absolute;
top: 40%;right: 0;
}
</style>
</head>
<body>
<div id="slider">
<div class="container">
<div id="sliderCicle">
<span></span>
<span></span>
<span></span>
</div>
<div id="pt">
<img src="./images/1.jpg" alt="1">
<img src="./images/2.jpg" alt="2">
<img src="./images/3.jpg" alt="3">
</div>
<div id="prev">
<img src="./images/l.png" alt="" style="margin-top:16px;">
</div>
<div id="next">
<img src="./images/r.png" alt="" style="margin-top:16px;">
</div>
</div>
</div>
</body>
<script>
var cicle = document.getElementsByTagName('span');
var cont = document.getElementsByClassName('container')[0];
var images = pt.getElementsByTagName('img');
var prev=document.getElementById('prev');
var next=document.getElementById('next');
var index=0;
var len = images.length;
//写一个箭头背景促发事件
cont.onmousemove=function(){
prev.style.background="rgba(0,0,0,.6)";
next.style.background="rgba(0,0,0,.6)";
}
cont.onmouseout=function(){
prev.style.background="";
next.style.background="";
}
//圆点触发事件
for (var x = 0; x < cicle.length; x++) {
(function(x){
cicle[x].onmousemove=function()
{
clearInterval(timer);
for (var i = 0; i < cicle.length; i++) {
cicle[i].style.backgroundColor='rgba(255,255,255,0)';
images[i].style.opacity = '0';
}
cicle[x].style.backgroundColor='rgba(255,255,255,1)';
images[x].style.opacity='1';
images[x].style.transition="1s";
}
cicle[x].onmouseout=function()
{
index=x;
timer=setInterval(run,3000);
this.style.background='rgba(255,255,255,1)';
}
})(x)
}
var timer;
timer = setInterval(run,3000);
function run(){
images[index].style.opacity = '0';
cicle[index].style.backgroundColor = 'rgba(255,255,255,0)';
index = ++index == len ? 0 : index;
images[index].style.opacity = '1';
cicle[index].style.backgroundColor = 'rgba(255,255,255,1)';
images[index].style.transition="1s";
}
// 箭头的函数
function show(index)
{
for (var i = 0; i < cicle.length; i++) {
cicle[i].style.backgroundColor = '