Итак, я провел последние 8 часов, пытаясь построить собственную карусель, я новичок в jquery. У меня есть ошибка на втором слайде.Ошибка на втором слайде карусели
Если вы видите, когда я нажимаю на второй, появляется кнопка prev, но вместо этого она появляется только во втором щелчке.
Вот мой код:
$(document).ready(function() {
var sliderWidth = 300; // Give the size of the window
var sliderV = $('#slide-wrap-vertical'); // Assigns the container that has all the sectiosn that will be scrolled vertically
var sliderCount = $('#slide-wrap-vertical').children().size(); // Gets the size of the vertical slider
var sliderHeight = sliderCount * sliderWidth; // Takes the height of the slider
$('#slide-wrap-vertical').css('height', sliderHeight); // assigns the height
//$('a.temp').text(sliderHeight);
showHideDirection();
$('a.nav-top-prev').on('click',function() {
$('#slide-wrap-vertical > div').animate({
'top': '+=' + sliderWidth + 'px'
}, 500);
showHideDirection();
});
$('a.nav-top-next').on('click', function() {
$('#slide-wrap-vertical > div').animate({
'top': '-=' + sliderWidth + 'px'
}, 500);
showHideDirection();
});
function showHideDirection() {
$(sliderV).children().each(function(){ // Checks all the children of the vertical carousel
if ($(this).position().top == 0) {
var index = $(this).index();
$('a.nav-top-prev').toggle(index!==0);
$('a.nav-top-next').toggle(index!==sliderCount-1);
}
});
}
});
Я добавил jsfiddle, а если вы хотите увидеть функциональность
http://jsfiddle.net/Dethdoll/WkFVs/12/
Ничего себе, спасибо! Я добавил вызов функции внутри анимации, но не так. Спасибо – Monica
Я очень ценю ваши заметки. Спасибо, что дает мне больше инструментов и знаний для завершения этого проекта. – Monica