Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sliding on mobile device scrolls entire page #1281

Open
randallreedjr opened this issue Jun 21, 2018 · 12 comments
Open

Sliding on mobile device scrolls entire page #1281

randallreedjr opened this issue Jun 21, 2018 · 12 comments

Comments

@randallreedjr
Copy link
Contributor

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
Copy link
Contributor Author

May share a root cause with #1240

@randallreedjr
Copy link
Contributor Author

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.

@renetalk
Copy link

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

@Eth3rnit3
Copy link

Eth3rnit3 commented Apr 5, 2019

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

.slick-slider {
  overflow: hidden;
}

@kingalione
Copy link

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

@kingalione
Copy link

Or just disable the arrows thats working better.

@AndersonFerreira07
Copy link

.slick-slider {
overflow: hidden;
}

funcional para mim, valeu mesmo!!!

@p-akash
Copy link

p-akash commented Apr 2, 2020

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

@ghost
Copy link

ghost commented Jun 11, 2020

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

Now It will works.

@lordival
Copy link

lordival commented Aug 5, 2022

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

Now It will works.

still not working for me. dots still gone

@mgurjanov
Copy link

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.

@Miguel-Angel-Guate
Copy link

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;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

9 participants