为什么循环一圈之后图片卡在最后一张了 小圆点正常
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>jquery实现轮播图</title>
<link rel="stylesheet" href="css/lunbotu.css">
<script type="text/javascript" src="js/jquery-1.12.4.js"></script>
<script type="text/javascript" src="js/lunbotu.js"></script>
</head>
<body>
<div class="main">
<div class="banner">
<a href="">
<div class="banner-slide slide1 slide-active"></div>
</a>
<a href="">
<div class="banner-slide slide2"></div>
</a>
<a href="">
<div class="banner-slide slide3"></div>
</a>
<a href="">
<div class="banner-slide slide4"></div>
</a>
<a href="">
<div class="banner-slide slide5"></div>
</a>
</div>
<a href="javascript:;" class="button prev" id="prev"></a>
<a href="javascript:;" class="button next" id="next"></a>
<div class="dots" id="dots">
<span class="active"></span>
<span></span>
<span></span>
<span></span>
<span></span>
</div>
</div>
</body>
</html>
*{
padding: 0;
margin: 0;
}
.main{
width: 1200px;
height: 460px;
overflow: hidden;
margin: 30px auto;
position: relative;
}
.banner{
width: 1200px;
height: 460px;
overflow: hidden;
position: relative;
}
.banner-slide{
width: 1200px;
height: 460px;
background-repeat: no-repeat;
position: absolute;
display: none;
}
.slide-active {
display: block;
}
.slide1 {
background-image: url("../img/1.jpg");
}
.slide2 {
background-image: url("../img/2.jpg");
}
.slide3 {
background-image: url("../img/3.jpg");
}
.slide4 {
background-image: url("../img/4.jpg");
}
.slide5 {
background-image: url("../img/5.jpg");
}
.button.prev{
position: absolute;
width: 40px;
height: 80px;
left:0;
top: 50%;
margin-top: -40px;
background: url("../img/pre2.png") no-repeat center center;
}
.button.next{
position: absolute;
width: 40px;
height: 80px;
right:0;
top: 50%;
margin-top: -40px;
background: url("../img/pre.png") no-repeat center center;
}
.button:hover{
background-color: #333;
opacity: 0.8;
}
.dots{
position: absolute;
right: 20px;
bottom: 24px;
}
.dots span{
display: inline-block;
width: 12px;
height: 12px;
border-radius: 50%;
background: rgba(7,17,27,0.4);
box-shadow: 0 0 0 2px rgba(255,255,255,0.8) inset;
}
.dots span.active{
background: #fff;
box-shadow: 0 0 0 2px rgba(7,17,27,0.4) inset;
}
$(function () {
var index = 0,
timer = null,
main = $('.main'),
pics = $('.banner-slide'),
len = pics.length,
dots = $('.dots>span'),
prev = $('.prev'),
next = $('.next')
function changeImg() {
pics.eq(index).addClass('slide-active').siblings().removeClass('slide-active');
dots.eq(index).addClass('active').siblings().removeClass('active');
}
function slideimg() {
main.mouseover(function () {
stopplay()
}).mouseout(function () {
startplay()
})
}
slideimg()
function startplay() {
timer = setInterval(function () {
index++;
if (index >= len) index = 0;
changeImg()
}, 2000)
}
function stopplay() {
if (timer) clearInterval(timer)
}
main.mouseout();
})
正在回答 回答被采纳积分+1
- 参与学习 人
- 提交作业 11218 份
- 解答问题 36712 个
从一个不会编程的小白到一个老司机是需要过程的,首先得入门,学习基础知识,然后才能进阶,最后再到精通,本专题是你走进前端世界的不二选择!
了解课程
恭喜解决一个难题,获得1积分~
来为老师/同学的回答评分吧
0 星