無限ループを取得しようとしていますが、しばらくすると「最大呼び出しスタック サイズを超えました」というエラーが表示されます。これは、それ自体に再帰的な無限ループが原因であることがわかりましたが、その無限ループが必要なため、コードが正しくない理由がわかりません。
これは、「スライド」関数を呼び出すために使用するコードです。
// The plugin usage => "Rock and Roll"
function activate() {
// Check or we need to wait, when a user hovers the main element
if (hoverState === false) {
// And "Rock and Roll"
if (opt.nav === false) {
slide(opt.effect);
} else {
// The navigation is used
$(opt.navArea + ' a').click(function () {
if ($(this).attr('id') === opt.next) {
// Slide to the next slide
slide(opt.effect, 'right');
} else if ($(this).attr('id') === opt.prev) {
slide(opt.effect, 'left');
}
}, function () {
slide(opt.effect);
});
}
}
}
// Activate the plugin after the pause has ended
setTimeout(activate, opt.pause + opt.speed);
私のコードにはいくつかの追加オプションがありますが、私がやろうとしているのは、(例として) 3000ms 後に関数のアクティブ化を呼び出して次のスライドに移動することです。しかし、前に言ったように、「最大呼び出しスタック サイズを超えました」というエラーが発生します。opt.nav の現在の状態は false です。
スライド機能
// Slide the content
function slide( effect, dir ) {
// The direction
dir = typeof dir !== 'undefined' ? dir : 'right';
// Define the current slide
var currSlide = $('li.active');
// Define the next slide
var nextSlide;
if( dir === 'right' ) {
nextSlide = currSlide.index() + 1;
// Check or the next slide is avaiable
if( nextSlide > ( elListSize - 1) ) {
nextSlide = 0;
}
} else if( dir === 'left' ) {
nextSlide = currSlide.index() - 1;
// Check or next slide is avaiable
if( nextSlide === 0) {
nextSlide = elListSize - 1;
}
}
// The fade function
if( effect === 'fade' ) {
// Fade the current slide out
currSlide.fadeOut(opt.speed, function() {
// Remove the active class from the current slide
currSlide.removeClass('active');
// Fade the next slide in an give it the class active
elListItem.eq(nextSlide).fadeIn(opt.speed, function() {
elListItem.eq(nextSlide).addClass('active');
});
});
}
} // End of the slide function