mirror of
https://github.com/pagefaultgames/pokerogue.git
synced 2025-04-06 18:10:04 +01:00
* #1326: add touchstart event to dpadCenter to prevent zoom behavior * #1326: improve variable naming for preventElementZoom * #1326: change selector to "#dpad" instead of just "#dpadCenter"
This commit is contained in:
parent
f4acf8bfc3
commit
8824082ceb
@ -115,3 +115,29 @@ function bindKey(node, key, buttonMap) {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@link https://stackoverflow.com/a/39778831/4622620|Source}
|
||||||
|
*
|
||||||
|
* Prevent zoom on specified element
|
||||||
|
* @param {HTMLElement} element
|
||||||
|
*/
|
||||||
|
function preventElementZoom(element) {
|
||||||
|
element.addEventListener("touchstart", (event) => {
|
||||||
|
const currentTouchTimeStamp = event.timeStamp;
|
||||||
|
const previousTouchTimeStamp = event.currentTarget.dataset.lastTouchTimeStamp || currentTouchTimeStamp;
|
||||||
|
const timeStampDifference = currentTouchTimeStamp - previousTouchTimeStamp;
|
||||||
|
const fingers = event.touches.length;
|
||||||
|
event.currentTarget.dataset.lastTouchTimeStamp = currentTouchTimeStamp;
|
||||||
|
|
||||||
|
if (!timeStampDifference || timeStampDifference > 500 || fingers > 1) {
|
||||||
|
return;
|
||||||
|
} // not double-tap
|
||||||
|
|
||||||
|
event.preventDefault();
|
||||||
|
event.target.click();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
const dpadDiv = document.querySelector("#dpad");
|
||||||
|
preventElementZoom(dpadDiv);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user