Skip to content

Commit c9b270e

Browse files
committed
feat: prevent blocked vertical scrolling on touch event
1 parent 939aac1 commit c9b270e

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

src/Swipe.svelte

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@
114114
115115
116116
let touch_active = false;
117+
let ts
117118
118119
function onMove(e){
119120
if (touch_active) {
@@ -124,6 +125,12 @@
124125
if(((pos_axis == 0 && (axis < _axis)) || (pos_axis == availableMeasure && (axis > _axis)))){
125126
return;
126127
}
128+
const te = e.touches ? e.touches[0].clientX : e.clientX
129+
const isVerticalScroll = Math.abs(ts - te) < 5
130+
if (!is_vertical && isVerticalScroll) {
131+
// prevent blocked scroll when user attempts vertical scrolling
132+
return
133+
}
127134
e.preventDefault();
128135
129136
if (distance <= availableMeasure && distance >= 0) {
@@ -142,6 +149,7 @@
142149
e.stopPropagation();
143150
touch_active = true;
144151
longTouch = false;
152+
ts = e.touches ? e.touches[0].clientX : e.clientX
145153
setTimeout(function() {
146154
longTouch = true;
147155
}, 250);

0 commit comments

Comments
 (0)