我想用简单的分页制作简单的 jQuery 渐变轮播。
一切正常。但是当我单击NEXT
按钮时,轮播每次都会返回到第一项。
如何解决这个问题?
小提琴
如果小提琴过时,请参阅我的 HTML:
<body>
<ul id="carousel">
<li class="is-showing" ><img src="http://aarontennyson.com/tutorials/demos/slide_show_fade/images/slide1.jpg" width="960" height="375" alt="image 1" /></li>
<li class="is-showing" ><img src="http://aarontennyson.com/tutorials/demos/slide_show_fade/images/slide2.jpg" width="960" height="375" alt="image 2" /><li>
<li class="is-showing" ><img src="http://aarontennyson.com/tutorials/demos/slide_show_fade/images/slide3.jpg" width="960" height="375" alt="image 3" /></li>
<li class="is-showing" ><img src="http://aarontennyson.com/tutorials/demos/slide_show_fade/images/slide4.jpg" width="960" height="375" alt="image 4" /></li>
<li class="is-showing" ><img src="http://aarontennyson.com/tutorials/demos/slide_show_fade/images/slide5.jpg" width="960" height="375" alt="image 5" /></li>
</ul>
<span class="prev">prev</span>
<span class="next">next</span>
</body>
和脚本:
$(document).ready(function() {
slideShow();
});
function slideShow() {
var showing = $('#carousel .is-showing');
var next = showing.next().length ? showing.next() : showing.parent().children(':first');
showing.fadeOut(800, function() {
next.fadeIn(800).addClass('is-showing');
}).removeClass('is-showing');
setTimeout(slideShow, 5000);
$(".next").click(function() {
showing.fadeOut(800, function() {
next.fadeIn(800).addClass('is-showing');
}).removeClass('is-showing');
})
}