Skip to content

Commit

Permalink
fix(virtual): fix when Element not swiping in Safari
Browse files Browse the repository at this point in the history
fixes #7679
  • Loading branch information
nolimits4web committed Jan 31, 2025
1 parent a3fee36 commit 5abdbfd
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
7 changes: 7 additions & 0 deletions src/core/slide/slideTo.mjs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { getBrowser } from '../../shared/get-browser.mjs';
import { animateCSSModeScroll } from '../../shared/utils.mjs';

export default function slideTo(index = 0, speed, runCallbacks = true, internal, initial) {
Expand Down Expand Up @@ -151,6 +152,12 @@ export default function slideTo(index = 0, speed, runCallbacks = true, internal,
}
return true;
}

const browser = getBrowser();
const isSafari = browser.isSafari;
if (isVirtual && !initial && isSafari && swiper.isElement) {
swiper.virtual.update(false, false, slideIndex);
}
swiper.setTransition(speed);
swiper.setTranslate(translate);
swiper.updateActiveIndex(slideIndex);
Expand Down
5 changes: 3 additions & 2 deletions src/modules/virtual/virtual.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export default function Virtual({ swiper, extendParams, on, emit }) {
return slideEl;
}

function update(force, beforeInit) {
function update(force, beforeInit, forceActiveIndex) {
const {
slidesPerView,
slidesPerGroup,
Expand All @@ -81,7 +81,8 @@ export default function Virtual({ swiper, extendParams, on, emit }) {
swiper.updateActiveIndex();
}

const activeIndex = swiper.activeIndex || 0;
const activeIndex =
typeof forceActiveIndex === 'undefined' ? swiper.activeIndex || 0 : forceActiveIndex;

let offsetProp;
if (swiper.rtlTranslate) offsetProp = 'right';
Expand Down

0 comments on commit 5abdbfd

Please sign in to comment.