Last active
June 25, 2021 20:10
-
-
Save sudofox/dab3276d6aec1e9223eb64554f4f8364 to your computer and use it in GitHub Desktop.
used for testing support of touch events/touch force on ios
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!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