改了一种形式 请问为什么imglist.style.left=-1520*index+"px";无法执行图片切换
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<style>
*{
padding:0;
}
#outer{
width:1500px;
height: 700px;
padding:10px 0;
position: relative;
overflow: hidden;
}
#imglist{
list-style: none;
position:absolute;
/*idth:7600px;*/
/*left: -1520px;*/
}
#imglist li{
float: left;
margin:0 10px;
}
#nav{
position: absolute;
bottom: 30px;
}
#nav a{
width:20px;
height:20px;
border-radius: 10px;
float: left;
background-color: rgb(14, 93, 99);
margin:0 5px;
opacity: 0.5;
}
#nav a:hover{
background-color: black;
}
</style>
<script type="text/javascript">
window.onload=function(){
var imglist=document.getElementById("imglist");
var imgArr=document.getElementsByTagName("img");
imglist.style.width=1520*imgArr.length+"px";
var imgdiv=document.getElementById("nav");
var outer=document.getElementById("outer");
nav.style.left=(outer.offsetWidth-nav.offsetWidth)/2+"px";
var index=0;
var allA=document.getElementsByTagName("a");
allA[index].style.backgroundColor="black";
for(var i=0;i<allA.length;i++){
allA[i].num = i;
allA[i].onclick=function(){
clearInterval(timer);
index=this.num;
imglist.style.left=-1520*index+"px";
setA();
move(imglist,"left",-1520*index,50,function(){
autoChange();
});
};
}
autoChange();
function setA(){
if(index>=imgArr.length-1){
index=0;
imglist.style.left=0;
}
for(var i=0;i<allA.length;i++){
allA[i].style.backgroundColor="";
}
allA[index].style.backgroundColor="black";
};
var timer;
function autoChange(){
//定时器
timer=setInterval(function(){
index++;//索引自增
index%=imgArr.length;
move(imglist,"left",-1520*index,20,function(){
setA();
})
},3000);
}
};
</script>
</head>
<body>
<div id="outer">
<ul id="imglist">
<li><img src="photo/1.jpg" alt="1"></li>
<li><img src="photo/2.jpg" alt="2"></li>
<li><img src="photo/3.jpg" alt="3"></li>
<li><img src="photo/4.jpeg" alt="4"></li>
<li><img src="photo/5.jpg" alt="5"></li>
</ul>
<div id="nav">
<a href=""></a>
<a href=""></a>
<a href=""></a>
<a href=""></a>
<a href=""></a>
</div>
</div>
</body>
</html>