Skip to content
This repository was archived by the owner on Jul 8, 2025. It is now read-only.

Commit 6a1505b

Browse files
author
Robert-brainhub
committed
fix: disable scroll on carousel swipe
1 parent 759c96a commit 6a1505b

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

src/components/Carousel.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,8 @@ export default class Carousel extends Component {
8282
if (this.node) {
8383
this.node.ownerDocument.addEventListener('mousemove', this.onMouseMove, true);
8484
this.node.ownerDocument.addEventListener('mouseup', this.onMouseUpTouchEnd, true);
85-
this.node.ownerDocument.addEventListener('touchstart', this.onTouchStart, { passive: false });
86-
this.node.ownerDocument.addEventListener('touchmove', this.onTouchMove, true);
85+
this.node.ownerDocument.addEventListener('touchstart', this.onTouchStart, true);
86+
this.node.ownerDocument.addEventListener('touchmove', this.onTouchMove, { passive: false });
8787
this.node.ownerDocument.addEventListener('touchend', this.onMouseUpTouchEnd, true);
8888
}
8989

@@ -313,10 +313,6 @@ export default class Carousel extends Component {
313313
* @param {number} index of the element drag started on
314314
*/
315315
onTouchStart = (e, index) => {
316-
if (this.state.dragStart) {
317-
e.preventDefault();
318-
e.stopPropagation();
319-
}
320316
this.setState({
321317
clicked: index,
322318
dragStart: e.changedTouches[0].pageX,
@@ -328,6 +324,10 @@ export default class Carousel extends Component {
328324
* @param {event} e event
329325
*/
330326
onTouchMove = e => {
327+
if (Math.abs(this.state.dragOffset) > 10) {
328+
e.preventDefault();
329+
e.stopPropagation();
330+
}
331331
if (this.state.dragStart !== null) {
332332
this.setState({
333333
dragOffset: e.changedTouches[0].pageX - this.state.dragStart,

0 commit comments

Comments
 (0)