<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<link rel="stylesheet" href="CSS_turn_take.css">
<body>
<div class="outor">
<div class="img">
<ul>
<li><a href="#"><img src="image/2560CDXCBJ_003008.jpg" alt=""></a></li>
<li><a href="#"><img src="image/2560CDXCBJ_003007.jpg" alt=""></a></li>
<li><a href="#"><img src="image/2560CDXCBJ_003006.jpg" alt=""></a></li>
<li><a href="#"><img src="image/2560CDXCBJ_003001.jpg" alt=""></a></li>
<li><a href="#"><img src="image/2560CDXCBJ_002020.jpg" alt=""></a></li>
<li><a href="#"><img src="image/2560CDXCBJ_002019.jpg" alt=""></a></li>
</ul>
</div>
<ul class="btn">
</ul>
<div class="btn_left button"> < </div>
<div class="btn_right button"> > </div>
</div>
关键是下面
<script src="jquery-3.1.1.js"></script>
<script>
var $img_index=$(".img li").length;
for(var i=0;i<$img_index;i++){
$(".btn").append("<li></li>");
}
实现鼠标点击
$(".btn li").eq(0).css("background-color","red");
$(".btn li").mouseover(function () {
var btn_index=$(this).index();
$(this).css("background-color","red").siblings().css("background-color","white");
$(".img li").eq(btn_index).stop().fadeIn(1000).siblings().stop().fadeOut(1000);
});
var clock=setInterval(turn,1500);
var i=0;
function turn() {
if(i==$img_index-1){
i=-1;
}
i++;
$(".img li").eq(i).stop().fadeIn(1000).siblings().stop().fadeOut(1000);
$(".btn li").eq(i).css("background-color","red").siblings().css("background-color","white");
}
$(".outor").hover(function () {
clearInterval(clock);
},function () {
clock=setInterval(turn,1500);
})
$(".btn_left").click(function () {
i--;
console.log(i);
$(".img li").eq(i).stop().fadeIn(1000).siblings().stop().fadeOut(1000);
$(".btn li").eq(i).css("background-color","red").siblings().css("background-color","white");
if(i==0){
i=$img_index;
}
});
$(".btn_right").click(function () {
if(i==$img_index-1){
i=-1;
}
i++;
$(".img li").eq(i).stop().fadeIn(1000).siblings().stop().fadeOut(1000);
$(".btn li").eq(i).css("background-color","red").siblings().css("background-color","white");
});
</script>
</body>
</html>
CSS代码
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
*{
margin: 0px;
padding: 0px;
}
.outor{
700px;
height: 400px;
margin: 100px auto;
position: relative;
}
.img a img{
700px;
height: 400px;
}
.img li{
position: absolute;
left: 0px;
list-style: none;
}
.btn{
position: absolute;
left: 220px;
top: 350px;
color: red;
}
.btn li{
display: inline-block;
list-style: none;
20px;
height: 20px;
text-align: center;
line-height: 20px;
margin-left: 15px;
background-color: white;
border-radius: 50%;
}
.button{
position: absolute;
35px;
height: 50px;
background-color: grey;
font-size: 30px;
font-weight: bolder;
color: white;
text-align: center;
line-height: 50px;
opacity: 0.6;
display: none;
}
.btn_left{
top: 175px;
left: 0px;
}
.btn_right{
right: 0px;
top: 175px;
}
.outor:hover .button{
display: block;
}
.background_color{
background-color: red;
}