Skip to content

Commit 192f7cc

Browse files
committed
[#837] Fix mous scroll and mobile swipe
1 parent a597404 commit 192f7cc

2 files changed

Lines changed: 14 additions & 4 deletions

File tree

src/components/ImageGallery.tsx

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,16 @@ const ImageGallery = forwardRef<ImageGalleryRef, ImageGalleryProps>(
310310

311311
if (disableSwipe) return;
312312

313+
// Once the swipe direction is locked to the gallery's slide axis,
314+
// prevent the browser from scrolling the page during the gesture.
315+
// Only affects touch devices (useSwipeHandlers listens to touch only).
316+
if (
317+
(!slideVertically && swipingLeftRightRef.current) ||
318+
(slideVertically && swipingUpDownRef.current)
319+
) {
320+
event.preventDefault();
321+
}
322+
313323
if (stopPropagation) {
314324
event.preventDefault();
315325
}

styles/image-gallery.css

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -291,8 +291,6 @@
291291
backface-visibility: hidden;
292292
-webkit-transform: translateZ(0);
293293
transform: translateZ(0);
294-
/* Prevent overscroll during swipe */
295-
overscroll-behavior: contain;
296294
touch-action: pan-y pinch-zoom;
297295
}
298296

@@ -303,13 +301,15 @@
303301
.image-gallery-slides {
304302
overflow: hidden;
305303
position: relative;
306-
touch-action: none;
304+
/* Allow vertical scroll and pinch-zoom; block horizontal pan so JS handles swipe.
305+
The browser's built-in direction detection prevents vertical scroll during
306+
horizontal swipes. On desktop, wheel/trackpad scroll passes through normally. */
307+
touch-action: pan-y pinch-zoom;
307308
/* GPU acceleration for smooth swiping */
308309
-webkit-backface-visibility: hidden;
309310
backface-visibility: hidden;
310311
contain: layout style paint;
311312
isolation: isolate;
312-
overscroll-behavior: none;
313313
}
314314

315315
/* Flex container that holds all slides and gets transformed */

0 commit comments

Comments
 (0)