diff --git a/client/js/src/page-scrolling.js b/client/js/src/page-scrolling.js new file mode 100644 index 00000000..7e17df59 --- /dev/null +++ b/client/js/src/page-scrolling.js @@ -0,0 +1,16 @@ +export function bindPageScrolling(canvas) { + // Miniquad cancels every touch, including swipes meant for the surrounding BGS page. + // Let the browser scroll and generate compatibility mouse events for taps instead. + const nativeTouch = (event) => event.stopImmediatePropagation(); + for (const type of ["touchstart", "touchmove", "touchend", "touchcancel"]) + canvas.addEventListener(type, nativeTouch, { capture: true, passive: true }); + canvas.style.touchAction = "pan-y pinch-zoom"; + canvas.addEventListener( + "wheel", + (event) => { + if (!event.ctrlKey && !event.metaKey && !document.fullscreenElement) + event.stopImmediatePropagation(); + }, + { capture: true, passive: true }, + ); +} diff --git a/client/js/src/run.js b/client/js/src/run.js index 75e1cff1..deb6c2b1 100644 --- a/client/js/src/run.js +++ b/client/js/src/run.js @@ -1,3 +1,4 @@ +import { bindPageScrolling } from "./page-scrolling"; import init, { set_wasm } from "../../dist/remote_client"; function dynamicallyLoadScript(url, onload) { @@ -9,6 +10,7 @@ function dynamicallyLoadScript(url, onload) { } export async function run({ selector, control }) { + bindPageScrolling(document.querySelector(selector)); let wbg = await init(); miniquad_add_plugin({ register_plugin: (a) => {