Skip to content

Commit 3dd8e27

Browse files
authored
use screenX/Y
1 parent 80dd54d commit 3dd8e27

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

MUSICPLAYER.html

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -433,19 +433,21 @@
433433
var end = {};
434434
var tracking = false;
435435
var thresholdTime = 500;
436-
var thresholdDistance = 75;
436+
var relativeScreenDistThreshold = 0.3 * (mobileCheck() ? 0.5 : 1);
437+
// 15-30% of the visible diagonal of the screen. should work seamlessly for any device/viewport, where mobile device swipes are more sensitive.
438+
var thresholdDistance = ((window.visualViewport?.height ?? 1)**2 + (window.visualViewport?.width ?? 1)**2)**0.5 * relativeScreenDistThreshold;
437439
gestureStart = function(e) {
438440
tracking = true;
439441
/* Hack - would normally use e.timeStamp but it's whack in Fx/Android */
440442
start.t = new Date().getTime();
441-
start.x = e.clientX;
442-
start.y = e.clientY;
443+
start.x = e.screenX;
444+
start.y = e.screenY;
443445
};
444446
gestureMove = function(e) {
445447
if (tracking) {
446448
e.preventDefault();
447-
end.x = e.clientX;
448-
end.y = e.clientY;
449+
end.x = e.screenX;
450+
end.y = e.screenY;
449451
}
450452
}
451453
gestureEnd = function(e) {
@@ -474,10 +476,10 @@
474476
}
475477
}
476478
}
477-
handle_gesture_left = function() { write2log(`Gesture fired: LEFT`, 1); audio_element.currentTime = 0; }
478-
handle_gesture_right = function() { write2log(`Gesture fired: RIGHT`, 1); load_song_from_index(); }
479-
handle_gesture_up = function() { write2log(`Gesture fired: UP`, 1); document.querySelector('#shuffle_button').click(); }
480-
handle_gesture_down = function() { write2log(`Gesture fired: DOWN`, 1); load_song_from_index(); }
479+
handle_gesture_left = function() { write2log(`Gesture fired: LEFT`, 1); document.querySelector('audio').currentTime = 0; }
480+
handle_gesture_right = function() { write2log(`Gesture fired: RIGHT`, 1); load_song_from_index(); }
481+
handle_gesture_up = function() { write2log(`Gesture fired: UP`, 1); document.querySelector('#shuffle_button').click(); }
482+
handle_gesture_down = function() { write2log(`Gesture fired: DOWN`, 1); load_song_from_index(); }
481483

482484
args.forEach(item=>{
483485
item.step = item.step.toLowerCase();

0 commit comments

Comments
 (0)