@@ -10,6 +10,7 @@ type OverflowHiddenMobileStyleType = 'top' | 'width' | 'height' | 'overflow' | '
10
10
11
11
let lockedNum = 0
12
12
let initialClientY = 0
13
+ let initialClientX = 0
13
14
let unLockCallback : any = null
14
15
let documentListenerAdded = false
15
16
@@ -67,14 +68,28 @@ const preventDefault = (event: TouchEvent) => {
67
68
}
68
69
69
70
const handleScroll = ( event : TouchEvent , targetElement : HTMLElement ) => {
70
- const clientY = event . targetTouches [ 0 ] . clientY - initialClientY
71
-
72
71
if ( targetElement ) {
73
- const { scrollTop, scrollHeight, clientHeight } = targetElement
72
+ const {
73
+ scrollTop,
74
+ scrollLeft,
75
+ scrollWidth,
76
+ scrollHeight,
77
+ clientWidth,
78
+ clientHeight,
79
+ } = targetElement
80
+ const clientX = event . targetTouches [ 0 ] . clientX - initialClientX
81
+ const clientY = event . targetTouches [ 0 ] . clientY - initialClientY
82
+ const isVertical = Math . abs ( clientY ) > Math . abs ( clientX )
83
+
74
84
const isOnTop = clientY > 0 && scrollTop === 0
85
+ const isOnLeft = clientX > 0 && scrollLeft === 0
86
+ const isOnRight = clientX < 0 && scrollLeft + clientWidth + 1 >= scrollWidth
75
87
const isOnBottom = clientY < 0 && scrollTop + clientHeight + 1 >= scrollHeight
76
88
77
- if ( isOnTop || isOnBottom ) {
89
+ if (
90
+ ( isVertical && ( isOnTop || isOnBottom ) ) ||
91
+ ( ! isVertical && ( isOnLeft || isOnRight ) )
92
+ ) {
78
93
return preventDefault ( event )
79
94
}
80
95
}
@@ -104,6 +119,7 @@ const lock = (targetElement?: HTMLElement) => {
104
119
if ( targetElement && lockedElements . indexOf ( targetElement ) === - 1 ) {
105
120
targetElement . ontouchstart = ( event ) => {
106
121
initialClientY = event . targetTouches [ 0 ] . clientY
122
+ initialClientX = event . targetTouches [ 0 ] . clientX
107
123
}
108
124
109
125
targetElement . ontouchmove = ( event ) => {
0 commit comments