<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>轮播图</title>
<style>
*{
padding: 0;
margin: 0;
}
.box{
position: relative;
width: 392px;
height:300px;
border:1px solid #333;
margin: 150px auto;
overflow: hidden;
position: relative;
}
ul.ul{
position: absolute;
left: 0;
top: 0;
width:2744px;
height: 300px;
}
li{
list-style: none;
float: left;
}
li img{
width:392px;
height: 300px;
}
.btns{
width: 392px;
height: 50px;
position: absolute;
top: 50%;
margin-top: -25px;
}
.btns div{
width: 30px;
height: 100px;
line-height: 50px;
color: #333;
text-align: center;
}
.leftBtn{
float: left;
}
.rightBtn{
float: right;
}
.clear:after{
content: "";
display: block;
clear: both;
}
ul.cirs{
position: absolute;
bottom: 0;
left:0;
right: 0;
height: 30px;
display: flex;
justify-content: center;
align-items: center;
}
.cirs li{
float: left;
width: 10px;
height: 10px;
border-radius: 50%;
margin: auto 10px;
border: 1px solid #ff9;
}
.active{
background: #99f;
}
</style>
</head>
<body>
<div class="box clear">
<ul class="clear ul">
<li><img src="imags/t1.jpg"/></li>
<li><img src="imags/t2.jpg"/></li>
<li><img src="imags/t3.jpg"/></li>
<li><img src="imags/t4.jpg"/></li>
<li><img src="imags/t5.jpg"/></li>
<li><img src="imags/t6.jpg"/></li>
<li><img src="imags/t1.jpg"/></li>
</ul>
<ul class="cirs clear">
<li class="active"></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
</ul>
<div class="btns clear">
<div id="leftBtn" class="leftBtn"><</div>
<div id="rightBtn" class="rightBtn">></div>
</div>
</div>
<script src="./value.js"></script>
<script>
var leftBtn = document.getElementById("leftBtn");
var rightBtn = document.getElementById("rightBtn");
var ul = document.getElementsByTagName("ul")[0];
var box = document.getElementsByTagName("div")[0];
var lis = document.querySelectorAll(".cirs li");
var indanse = box.clientWidth;
var index = 0;
rightBtn.onclick = function(){
index++;
move(ul,{left:-index * indanse},1000,function(){
if(index === 6){
index = 0;
ul.style.left = 0;
}
colorCirs();
});
}
leftBtn.onclick = function(){
index--;
if(index < 0){
index = 6;
ul.style.left = -index * indanse + "px";
index--;
}
move(ul,{left:-index * indanse},1000,function(){
colorCirs();
});
}
for(var i = 0;i < lis.length;i++){
lis[i].onclick = function(){
index = i;
move(ul,{left:-index * indanse},1000,function(){
colorCirs();
})
}
}
function colorCirs(){
for(let i = 0; i < lis.length;i++){
lis[i].className = "";
}
lis[index].className = "active";
}
</script>
</body>