Возможно, что-то вроде этого:
РЕДАКТИРОВАТЬ: обработчики щелчков теперь позволят вам «зацикливаться» вперед и назад.
// a reference to the currently shown slide
// you will have to initialize this somewhere
var currentSlide;
jQuery("span.left-arrow").click(function() {
currentSlide.fadeOut(function(){
// if it has a previous sibling, use the previous sibling
// otherwise set it to the last slide
currentSlide = currentSlide.prev().length ? currentSlide.prev() : currentSlide.siblings().last();
currentSlide.fadeIn();
});
}
jQuery("span.right-arrow").click(function() {
currentSlide.fadeOut(function(){
currentSlide = currentSlide.next().length ? currentSlide.next() : currentSlide.siblings().first();
currentSlide.fadeIn();
});
}
Используя этот метод, выне обязательно присваивать каждому слайду уникальный идентификатор, но элементы слайда должны быть единственными дочерними элементами #home_slider
.
. Вы можете инициализировать что-то вроде:
jQuery(function(){
// this loops through all slides when the page loads and
// assigns the first slide to the variable currentSlide
// and hides all the others
jQuery("#home_slider").children().each(function(index){
index == 0 ? currentSlide = jQuery(this) : jQuery(this).hide();
});
}