diff --git a/src/core/loop/loopFix.js b/src/core/loop/loopFix.js index e14ee5bd1..813d52603 100644 --- a/src/core/loop/loopFix.js +++ b/src/core/loop/loopFix.js @@ -7,6 +7,7 @@ export default function loopFix({ setTranslate, activeSlideIndex, byController, + byMousewheel, } = {}) { const swiper = this; if (!swiper.params.loop) return; @@ -97,10 +98,13 @@ export default function loopFix({ const currentSlideTranslate = swiper.slidesGrid[activeIndex]; const newSlideTranslate = swiper.slidesGrid[activeIndex + slidesPrepended]; const diff = newSlideTranslate - currentSlideTranslate; - - swiper.slideTo(activeIndex + slidesPrepended, 0, false, true); - if (setTranslate) { - swiper.touches[swiper.isHorizontal() ? 'startX' : 'startY'] += diff; + if (byMousewheel) { + swiper.setTranslate(swiper.translate - diff); + } else { + swiper.slideTo(activeIndex + slidesPrepended, 0, false, true); + if (setTranslate) { + swiper.touches[swiper.isHorizontal() ? 'startX' : 'startY'] += diff; + } } } else { if (setTranslate) { @@ -112,10 +116,13 @@ export default function loopFix({ const currentSlideTranslate = swiper.slidesGrid[activeIndex]; const newSlideTranslate = swiper.slidesGrid[activeIndex - slidesAppended]; const diff = newSlideTranslate - currentSlideTranslate; - - swiper.slideTo(activeIndex - slidesAppended, 0, false, true); - if (setTranslate) { - swiper.touches[swiper.isHorizontal() ? 'startX' : 'startY'] += diff; + if (byMousewheel) { + swiper.setTranslate(swiper.translate - diff); + } else { + swiper.slideTo(activeIndex - slidesAppended, 0, false, true); + if (setTranslate) { + swiper.touches[swiper.isHorizontal() ? 'startX' : 'startY'] += diff; + } } } else { swiper.slideToLoop(slideRealIndex, 0, false, true); diff --git a/src/modules/mousewheel/mousewheel.js b/src/modules/mousewheel/mousewheel.js index 87eed36e3..9bde07fb7 100644 --- a/src/modules/mousewheel/mousewheel.js +++ b/src/modules/mousewheel/mousewheel.js @@ -282,6 +282,7 @@ export default function Mousewheel({ swiper, extendParams, on, emit }) { delta: Math.abs(delta), direction: Math.sign(delta), }; + const ignoreWheelEvents = lastEventBeforeSnap && newEvent.time < lastEventBeforeSnap.time + 500 && @@ -290,9 +291,6 @@ export default function Mousewheel({ swiper, extendParams, on, emit }) { if (!ignoreWheelEvents) { lastEventBeforeSnap = undefined; - if (swiper.params.loop) { - swiper.loopFix(); - } let position = swiper.getTranslate() + delta * params.sensitivity; const wasBeginning = swiper.isBeginning; const wasEnd = swiper.isEnd; @@ -309,6 +307,12 @@ export default function Mousewheel({ swiper, extendParams, on, emit }) { if ((!wasBeginning && swiper.isBeginning) || (!wasEnd && swiper.isEnd)) { swiper.updateSlidesClasses(); } + if (swiper.params.loop) { + swiper.loopFix({ + direction: newEvent.direction < 0 ? 'next' : 'prev', + byMousewheel: true, + }); + } if (swiper.params.freeMode.sticky) { // When wheel scrolling starts with sticky (aka snap) enabled, then detect