slideNext.js 826 Bytes
Newer Older
xhw committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
export default function slideNext(speed = this.params.speed, runCallbacks = true, internal) {
	const swiper = this;
	const {
		animating,
		enabled,
		params
	} = swiper;
	if (!enabled) return swiper;
	let perGroup = params.slidesPerGroup;

	if (params.slidesPerView === 'auto' && params.slidesPerGroup === 1 && params.slidesPerGroupAuto) {
		perGroup = Math.max(swiper.slidesPerViewDynamic('current', true), 1);
	}

	const increment = swiper.activeIndex < params.slidesPerGroupSkip ? 1 : perGroup;

	if (params.loop) {
		if (animating && params.loopPreventsSlide) return false;
		swiper.loopFix();
	}

	if (params.rewind && swiper.isEnd) {
		return swiper.slideTo(0, speed, runCallbacks, internal);
	}
	setTimeout(() => {
		swiper.slideTo(swiper.activeIndex + increment, speed, runCallbacks, internal)
	}, 0)
	return true;
}