aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAUTOMATIC1111 <16777216c@gmail.com>2023-04-29 19:43:34 +0300
committerGitHub <noreply@github.com>2023-04-29 19:43:34 +0300
commit45371704f6eea2d9c52bab1bd658f1ba2ba2620c (patch)
treed471fced38c56a7f5af5f249ca97fedb22133b6b
parente40b2d947d874ed5504701bfd8e32243e0c456eb (diff)
parent54291f9d63f0c7dc445b90f3afb37fc330739557 (diff)
Merge pull request #7632 from papuSpartan/gamepad
Image viewer scrolling via analog stick
-rw-r--r--javascript/imageviewerGamepad.js36
1 files changed, 36 insertions, 0 deletions
diff --git a/javascript/imageviewerGamepad.js b/javascript/imageviewerGamepad.js
new file mode 100644
index 00000000..29bd7140
--- /dev/null
+++ b/javascript/imageviewerGamepad.js
@@ -0,0 +1,36 @@
+ let delay = 350//ms
+ window.addEventListener('gamepadconnected', (e) => {
+ console.log("Gamepad connected!")
+ const gamepad = e.gamepad;
+ setInterval(() => {
+ const xValue = gamepad.axes[0].toFixed(2);
+ if (xValue < -0.3) {
+ modalPrevImage(e);
+ } else if (xValue > 0.3) {
+ modalNextImage(e);
+ }
+
+ }, delay);
+ });
+
+
+ /*
+ Primarily for vr controller type pointer devices.
+ I use the wheel event because there's currently no way to do it properly with web xr.
+ */
+
+ let isScrolling = false;
+ window.addEventListener('wheel', (e) => {
+ if (isScrolling) return;
+ isScrolling = true;
+
+ if (e.deltaX <= -0.6) {
+ modalPrevImage(e);
+ } else if (e.deltaX >= 0.6) {
+ modalNextImage(e);
+ }
+
+ setTimeout(() => {
+ isScrolling = false;
+ }, delay);
+ }); \ No newline at end of file