我有以下代码当图像少于三个时我面临问题它显示空白幻灯片它不能作为旋转器完美地工作我希望它像顺时针和逆时针方向的无限旋转器一样工作。
CSS
#slider-wrapper {
margin: 5% 10%;
max-height: 500px;
max-width: 300px;
position:relative;
}
#slider {
display: block;
position: relative;
z-index: 99999;
max-width: 710px;
width: 100%;
margin: 0 auto;
background: red;
}
#button-previous {
height: 60px;
left: -40px;
margin-top: 40%;
position: absolute;
width: 40px;
}
#button-next {
float: right;
margin-top: 40%;
position: relative;
}
.sp {
position: absolute;
}
#slider .sp {
max-width: 710px;
width: 100%;
max-height: 500px;
height: 40px;
}
JavaScript
$(document).ready(function(e) {
$("#slider > div:gt(0)").hide();
$("#button-next").click(function () {
$("#slider > div:first")
.fadeOut(1000)
.next()
.fadeIn(1000)
.appendTo("#slider");
});
$("#slider > div:gt(0)").hide();
$("#button-previous").click(function () {
$("#slider > div:last")
.fadeOut(1000)
.next()
.fadeIn(1000)
.appendTo("#slider");
});
});
HTML
<div id="slider-wrapper">
<div id="slider">
<div class="sp"><img src="Images/thumb/1.jpg" width="234" height="240"></div>
<div class="sp"><img src="Images/thumb/2.jpg" width="234" height="240"></div>
<div class="sp"><img src="Images/thumb/3.jpg" width="234" height="240"></div>
</div>
<div id="button-previous">prev</div>
<div id="button-next">next</div>
</div>