1010
1111let isLocked = false ;
1212let initialClientY = - 1 ;
13+ let initialClientX = - 1 ;
1314let scrolledClientY = 0 ;
1415// Adds this attribute to an inner scrollable element to allow it to scroll
1516export const SCROLL_LOCK_DISABLE_ATTR = 'data-scroll-lock-disable' ;
@@ -82,8 +83,10 @@ const isVerticalScroll = ({ scrollHeight, scrollWidth }) => scrollHeight > scrol
8283 * @return {boolean }
8384 */
8485function handleScroll ( event , target ) {
86+ const clientY = event . targetTouches [ 0 ] . clientY - initialClientY ;
87+ const clientX = event . targetTouches [ 0 ] . clientX - initialClientX ;
88+
8589 if ( isVerticalScroll ( target ) ) {
86- const clientY = event . targetTouches [ 0 ] . clientY - initialClientY ;
8790 if ( target . scrollTop === 0 && clientY > 0 ) {
8891 // element is at the top of its scroll.
8992 return preventDefault ( event ) ;
@@ -93,6 +96,9 @@ function handleScroll(event, target) {
9396 // element is at the bottom of its scroll.
9497 return preventDefault ( event ) ;
9598 }
99+ } else if ( Math . abs ( clientY ) > Math . abs ( clientX ) ) {
100+ // prevent event if user tries to perform vertical scroll in an horizontal scrolling element
101+ return preventDefault ( event ) ;
96102 }
97103
98104 // prevent the scroll event from going up to the parent/window
@@ -114,6 +120,7 @@ function advancedLock(targetElement) {
114120 if ( event . targetTouches . length === 1 ) {
115121 // detect single touch.
116122 initialClientY = event . targetTouches [ 0 ] . clientY ;
123+ initialClientX = event . targetTouches [ 0 ] . clientX ;
117124 }
118125 } ;
119126 targetElement . ontouchmove = ( event ) => {
0 commit comments