Skip to content

Commit

Permalink
Fix snapIndex routine
Browse files Browse the repository at this point in the history
Fixes #2269
  • Loading branch information
nolimits4web committed Oct 23, 2017
1 parent e7d2971 commit 56134c5
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 10 deletions.
15 changes: 9 additions & 6 deletions src/components/core/slide/slideTo.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,8 @@ export default function (index = 0, speed = this.params.speed, runCallbacks = tr
}

// Update Index
swiper.updateActiveIndex(slideIndex);

if ((rtl && -translate === swiper.translate) || (!rtl && translate === swiper.translate)) {
swiper.updateActiveIndex(slideIndex);
// Update Height
if (params.autoHeight) {
swiper.updateAutoHeight();
Expand All @@ -50,18 +49,22 @@ export default function (index = 0, speed = this.params.speed, runCallbacks = tr
}
return false;
}
swiper.updateSlidesClasses();

swiper.emit('beforeTransitionStart', speed, internal);
swiper.transitionStart(runCallbacks);

if (speed === 0 || Browser.lteIE9) {
swiper.setTransition(0);
swiper.setTranslate(translate);
swiper.updateActiveIndex(slideIndex);
swiper.updateSlidesClasses();
swiper.emit('beforeTransitionStart', speed, internal);
swiper.transitionStart(runCallbacks);
swiper.transitionEnd(runCallbacks);
} else {
swiper.setTransition(speed);
swiper.setTranslate(translate);
swiper.updateActiveIndex(slideIndex);
swiper.updateSlidesClasses();
swiper.emit('beforeTransitionStart', speed, internal);
swiper.transitionStart(runCallbacks);
if (!swiper.animating) {
swiper.animating = true;
$wrapperEl.transitionEnd(() => {
Expand Down
14 changes: 10 additions & 4 deletions src/components/core/update/updateActiveIndex.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import Utils from '../../../utils/utils';
export default function (newActiveIndex) {
const swiper = this;
const translate = swiper.rtl ? swiper.translate : -swiper.translate;
const { slidesGrid, snapGrid, params, activeIndex: previousIndex, realIndex: previousRealIndex } = swiper;
const { slidesGrid, snapGrid, params, activeIndex: previousIndex, realIndex: previousRealIndex, snapIndex: previousSnapIndex } = swiper;
let activeIndex = newActiveIndex;
let snapIndex;
if (typeof activeIndex === 'undefined') {
Expand All @@ -23,11 +23,17 @@ export default function (newActiveIndex) {
if (activeIndex < 0 || typeof activeIndex === 'undefined') activeIndex = 0;
}
}

snapIndex = Math.floor(activeIndex / params.slidesPerGroup);
if (snapGrid.indexOf(translate) >= 0) {
snapIndex = snapGrid.indexOf(translate);
} else {
snapIndex = Math.floor(activeIndex / params.slidesPerGroup);
}
if (snapIndex >= snapGrid.length) snapIndex = snapGrid.length - 1;

if (activeIndex === previousIndex) {
if (snapIndex !== previousSnapIndex) {
swiper.snapIndex = snapIndex;
swiper.emit('snapIndexChange');
}
return;
}

Expand Down

0 comments on commit 56134c5

Please sign in to comment.