react-slick icon indicating copy to clipboard operation
react-slick copied to clipboard

Sliding on mobile device scrolls entire page

Open randallreedjr opened this issue 6 years ago • 12 comments

I have only seen this happen on an actual mobile device, not in the mobile views available in either Chrome or Safari developer tools.

It appears to only affect iOS (confirmed on iPhone running 11.3 and iPhone 8 Plus running 11.4) and not Android.

React Slick mobile

react-slick-mobile

Slick mobile

slick-mobile

randallreedjr avatar Jun 21 '18 15:06 randallreedjr

May share a root cause with #1240

randallreedjr avatar Jun 21 '18 17:06 randallreedjr

This was my solution:

  constructor(props) {
    super(props);

    this.carouselSettings = {..., touchThreshold: 5, ...}; // explicitly set touchThreshold since we reference it later
    this.preventTouch = this.preventTouch.bind(this);
    this.touchStart = this.touchStart.bind(this);
  }

  componentDidMount() {
    // Disable touchmove to prevent scrolling entire page
    const carousel = document.getElementById('someid'); // Your site element containing react-slick's carousel-container
    carousel.addEventListener('touchstart', this.touchStart);
    carousel.addEventListener('touchmove', this.preventTouch, { passive: false });
  }

  touchStart(e) {
    // capture user's starting finger position, for later comparison
    this.firstClientX = e.touches[0].clientX;
  }

  preventTouch(e) {
    // only prevent touch on horizontal scroll (for horizontal carousel)
    // this allows the users to scroll vertically past the carousel when touching the carousel
    // this also stabilizes the horizontal scroll somewhat, decreasing vertical scroll while horizontal scrolling
    const clientX = e.touches[0].clientX - this.firstClientX;
    const horizontalScroll = Math.abs(clientX) > this.carouselSettings.touchThreshold;
    if (horizontalScroll) {
      e.preventDefault();
    }
  }

Thanks to @yunyong for his helpful comment.

randallreedjr avatar Jun 25 '18 14:06 randallreedjr

You can also solve this by giving the surrounding container a overflow: hidden

renetalk avatar Sep 14 '18 18:09 renetalk

That's right, @renetalk , but I'd like to point out that it's the react-slick container.

.slick-slider {
  overflow: hidden;
}

Eth3rnit3 avatar Apr 05 '19 21:04 Eth3rnit3

Problem with the overflow: hidden hack is that the dots are then missing and I'm not able to bring them back somehow

kingalione avatar Apr 26 '19 20:04 kingalione

Or just disable the arrows thats working better.

kingalione avatar Apr 27 '19 17:04 kingalione

.slick-slider { overflow: hidden; }

funcional para mim, valeu mesmo!!!

AndersonFerreira07 avatar Jan 15 '20 22:01 AndersonFerreira07

.slick-slider { overflow: hidden; } now dots are gone

p-akash avatar Apr 02 '20 12:04 p-akash

.slick-slider { overflow: hidden; } .slick-dots { position: static; }

Now It will works.

ghost avatar Jun 11 '20 11:06 ghost

.slick-slider { overflow: hidden; } .slick-dots { position: static; }

Now It will works.

still not working for me. dots still gone

lordival avatar Aug 05 '22 06:08 lordival

I used this solution:

.slick-list { max-width: 99%; }

Overflow X is gone and dots are visible. You might need to set/unset margins on mobile to center active slide.

mgurjanov avatar May 17 '23 11:05 mgurjanov

I used this solution because with the overflow hidden the dots was gone and with the line below it´s now dots are back .slick-slider { overflow: hidden; padding-bottom: 40px; } .slick-dots { //here you can customize the height height: 10vh; }

Miguel-Angel-Guate avatar Mar 12 '24 00:03 Miguel-Angel-Guate