J
J
JustWise12021-07-11 16:44:06
JavaScript
JustWise1, 2021-07-11 16:44:06

How to disable page scrolling when slider is at start or end with freeMode enabled?

If you set the freemode and mousewheel parameters to the slider and scroll to the extreme points (the first or last slide), then the whole page starts scrolling after that. That is, the slider works as if it had the mousewheel.releaseOnEdges option set to true.

I tried to solve this problem in this way, but it didn't work

let slider= new Swiper('.slider', {
  spaceBetween: 45,
  slidesPerView: 'auto',
  mousewheel: true,
  allowTouchMove: true,
  freeMode: true,
  scrollbar: {
    el: '.scroll',
    hide: false,
    draggable: true,
  },
  on: {
    scroll: function (swiper, event) {
      let scrollTop = window.pageYOffset || document.documentElement.scrollTop;
      let scrollLeft = window.pageXOffset || document.documentElement.scrollLeft;
      if (swiper.isBeginning || swiper.isEnd) {
        window.scrollTo(scrollLeft, scrollTop);
      }
    }
  }
});

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question