diff options
author | AUTOMATIC <16777216c@gmail.com> | 2023-05-01 14:27:53 +0300 |
---|---|---|
committer | AUTOMATIC <16777216c@gmail.com> | 2023-05-01 14:27:53 +0300 |
commit | fe8a10d428bcc6be9cc8efb9772eca9e40f98dc8 (patch) | |
tree | d1e0ff50e327c3c59230b39907284c20ffbf0fe3 /javascript/imageviewerGamepad.js | |
parent | 22bcc7be428c94e9408f589966c2040187245d81 (diff) | |
parent | 6fbd85dd0c0dffc06560bff91f4c4b65e441ca5f (diff) |
Merge branch 'release_candidate'
Diffstat (limited to 'javascript/imageviewerGamepad.js')
-rw-r--r-- | javascript/imageviewerGamepad.js | 36 |
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 |