Skip to content

Commit

Permalink
refactor(core/slide/slideTo): remove duplicate code (#5211)
Browse files Browse the repository at this point in the history
* refactor(core/slide/slideTo): remove duplicate code

* refactor(core/slide/slideTo): remove duplicate code
  • Loading branch information
lucasrleandro authored Dec 22, 2021
1 parent 51c4a49 commit decae49
Showing 1 changed file with 30 additions and 37 deletions.
67 changes: 30 additions & 37 deletions src/core/slide/slideTo.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,46 +165,39 @@ export default function slideTo(
return true;
}

swiper.setTransition(speed);
swiper.setTranslate(translate);
swiper.updateActiveIndex(slideIndex);
swiper.updateSlidesClasses();
swiper.emit('beforeTransitionStart', speed, internal);
swiper.transitionStart(runCallbacks, direction);

if (speed === 0) {
swiper.setTransition(0);
swiper.setTranslate(translate);
swiper.updateActiveIndex(slideIndex);
swiper.updateSlidesClasses();
swiper.emit('beforeTransitionStart', speed, internal);
swiper.transitionStart(runCallbacks, direction);
swiper.transitionEnd(runCallbacks, direction);
} else {
swiper.setTransition(speed);
swiper.setTranslate(translate);
swiper.updateActiveIndex(slideIndex);
swiper.updateSlidesClasses();
swiper.emit('beforeTransitionStart', speed, internal);
swiper.transitionStart(runCallbacks, direction);
if (!swiper.animating) {
swiper.animating = true;
if (!swiper.onSlideToWrapperTransitionEnd) {
swiper.onSlideToWrapperTransitionEnd = function transitionEnd(e) {
if (!swiper || swiper.destroyed) return;
if (e.target !== this) return;
swiper.$wrapperEl[0].removeEventListener(
'transitionend',
swiper.onSlideToWrapperTransitionEnd,
);
swiper.$wrapperEl[0].removeEventListener(
'webkitTransitionEnd',
swiper.onSlideToWrapperTransitionEnd,
);
swiper.onSlideToWrapperTransitionEnd = null;
delete swiper.onSlideToWrapperTransitionEnd;
swiper.transitionEnd(runCallbacks, direction);
};
}
swiper.$wrapperEl[0].addEventListener('transitionend', swiper.onSlideToWrapperTransitionEnd);
swiper.$wrapperEl[0].addEventListener(
'webkitTransitionEnd',
swiper.onSlideToWrapperTransitionEnd,
);
} else if (!swiper.animating) {
swiper.animating = true;
if (!swiper.onSlideToWrapperTransitionEnd) {
swiper.onSlideToWrapperTransitionEnd = function transitionEnd(e) {
if (!swiper || swiper.destroyed) return;
if (e.target !== this) return;
swiper.$wrapperEl[0].removeEventListener(
'transitionend',
swiper.onSlideToWrapperTransitionEnd,
);
swiper.$wrapperEl[0].removeEventListener(
'webkitTransitionEnd',
swiper.onSlideToWrapperTransitionEnd,
);
swiper.onSlideToWrapperTransitionEnd = null;
delete swiper.onSlideToWrapperTransitionEnd;
swiper.transitionEnd(runCallbacks, direction);
};
}
swiper.$wrapperEl[0].addEventListener('transitionend', swiper.onSlideToWrapperTransitionEnd);
swiper.$wrapperEl[0].addEventListener(
'webkitTransitionEnd',
swiper.onSlideToWrapperTransitionEnd,
);
}

return true;
Expand Down

0 comments on commit decae49

Please sign in to comment.