我知道可能之前有人问过这个,但我找不到合适的答案。 我想阻止这个函数循环:
var counter = 0;
var height, length, sec, inner;
var links = $('.projects li');
var containers = $('.projects .container');
$('.container #prev').click(function(){
counter = (--counter) < 0 ? length - 1 : counter%length;
console.log(counter);
inner.stop().animate({top: -counter*height }, 800);
//this is where it loops
});
$('.container #next').click(function(){
counter = (++counter) < 0 ? length - 1 : counter%length;
console.log(counter);
inner.stop().animate({top: -counter*height }, 800);
//this is where it loops
});
links.click(function(){
var index = links.index(this);
var container = $(containers[index]);
$(".projects_menu").css({'display':'none'});
container.addClass('active');
inner = container.find('.inner');
sec = container.find('section');
length = sec.length;
if (length < 2) {
console.log(1);
$('.container #prev, .container #next').css({'display':'none'});
}
height = $('.container').height();
});
非常感谢!