<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
*{
margin: 0;
padding: 0;
}
.body{
margin:0 auto;
width: 1300px;
overflow: hidden;
position: relative;
height: 400px;
background-color: yellow;
}
.img{
width: 999999px;
height: 400px;
overflow: hidden;
position: absolute;
/* left: -1300px; */
}
.img li img{
width: 1300px;
height: 400px;
float: left;
}
li{
list-style-type: none;
}
.prev,.next{
position:absolute;
width: 32px;
height: 32px;
top: 50%;
}
.prev{
background-image: url(./img/prev.png);
left: 40px;
}
.next{
background-image: url(./img/next.png);
right: 40px;
}
.count{
position: absolute;
width: 60px;
height: 10px;
margin: 0 auto;
bottom: 25px;
/* background-color: black; */
left: 612px;
}
.count li a{
width: 10px;
height: 10px;
cursor:pointer; /* 将鼠标形状设为手形 */
background-color:#ccc;
opacity: .5;/*不透明度,取值范围:[0,1]之间的一个数,可以是小数*/
float: left;
margin-left: 5px;
border-radius: 50%;/*圆角*/
}
.count .active{
background-color: slateblue;
opacity: 1;
}
</style>
</head>
<body>
<div class="body">
<ul class="img">
<li><img src="./img/banner_01.jpg" alt="介绍"></li>
<li><img src="./img/banner_02.jpg" alt="介绍"></li>
<li><img src="./img/banner_03.jpg" alt="banner"></li>
</ul>
<div class="control">
<div class="prev"></div>
<div class="next"></div>
</div>
<!-- 计数器 -->
<ul class="count">
<li><a class="active" href="javascript:;"></a></li>
<li><a href="javascript:;"></a></li>
<li><a href="javascript:;"></a></li>
</ul>
</div>
</body>
<script>
let allA = document.getElementsByTagName('a')
let allImg = document.getElementsByClassName('img')[0]
let img = allImg.getElementsByTagName('img')[0]
let width = getComputedStyle(img,null)['width']
for(i in allA){
allA[i].num = i
allA[i].onclick = function () {
for(j in allA){ //此处用for/in会报错 因为会遍历到非枚举型属性
/* this.style.backgroundColor = '#ccc' */
console.log(allA.hasOwnProperty(j))
}
this.style.backgroundColor = 'blue'
alert((-parseInt(width))*this.num +'px')
allImg.style.left = (-parseInt(width))*this.num +'px'
}
}
</script>
</html>