onScroll.js 904 B

1234567891011121314151617181920212223242526272829303132333435
  1. export default function onScroll() {
  2. const swiper = this;
  3. const {
  4. wrapperEl,
  5. rtlTranslate,
  6. enabled
  7. } = swiper;
  8. if (!enabled) return;
  9. swiper.previousTranslate = swiper.translate;
  10. if (swiper.isHorizontal()) {
  11. swiper.translate = -wrapperEl.scrollLeft;
  12. } else {
  13. swiper.translate = -wrapperEl.scrollTop;
  14. } // eslint-disable-next-line
  15. if (swiper.translate === -0) swiper.translate = 0;
  16. swiper.updateActiveIndex();
  17. swiper.updateSlidesClasses();
  18. let newProgress;
  19. const translatesDiff = swiper.maxTranslate() - swiper.minTranslate();
  20. if (translatesDiff === 0) {
  21. newProgress = 0;
  22. } else {
  23. newProgress = (swiper.translate - swiper.minTranslate()) / translatesDiff;
  24. }
  25. if (newProgress !== swiper.progress) {
  26. swiper.updateProgress(rtlTranslate ? -swiper.translate : swiper.translate);
  27. }
  28. swiper.emit('setTranslate', swiper.translate, false);
  29. }