Skip to content

Instantly share code, notes, and snippets.

@sudofox
Last active June 25, 2021 20:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sudofox/dab3276d6aec1e9223eb64554f4f8364 to your computer and use it in GitHub Desktop.
Save sudofox/dab3276d6aec1e9223eb64554f4f8364 to your computer and use it in GitHub Desktop.
used for testing support of touch events/touch force on ios
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Touch force test</title>
<style>
* {
font-family: monospace;
}
#debug {
word-break: break-all;
}
</style>
<script type="text/javascript">
function stringifyEvent(e) {
const obj = {};
for (let k in e) {
obj[k] = e[k];
}
return JSON.stringify(obj, (k, v) => {
if (v instanceof Node) return 'Node';
if (v instanceof Window) return 'Window';
return v;
}, '');
}
function logTouch(e) {
console.log(e);
document.getElementById("debug").innerText = "touches: " + stringifyEvent(e.touches[e.touches.length - 1]) + "\n"
+ "changedTouches: " + stringifyEvent(e.changedTouches[e.changedTouches.length - 1]) + "\n"
+ "targetTouches: " + stringifyEvent(e.targetTouches[e.targetTouches.length - 1]);
}
</script>
</head>
<body>
<div id="debug">Tap/swipe on the screen and look for a force value > 0</div>
</body>
<script>
document.addEventListener("touchstart", logTouch);
document.addEventListener("touchmove", logTouch);
</script>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment