Created
September 6, 2017 12:15
-
-
Save herrernst/131d1895e369ea6569bb954bfec0cefe to your computer and use it in GitHub Desktop.
safari touchmove event preventDefault
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> | |
<meta name="viewport" content="initial-scale=1"> | |
<h1>safari touchmove event preventDefault</h1> | |
<div style="width: 300px; height: 300px; background: green"></div> | |
<h2>works</h2> | |
<pre> | |
document.addEventListener("touchmove", (e) => e.preventDefault()) | |
</pre> | |
<h2>works</h2> | |
<pre> | |
document.addEventListener("touchstart", (e) => { | |
console.log("touchstart") | |
}) | |
document.addEventListener("touchmove", (e) => { | |
e.preventDefault(); | |
console.log("touchmove, should prevent") | |
}) | |
</pre> | |
<h2>doesn't work</h2> | |
<pre> | |
document.addEventListener("touchstart", (e) => { | |
console.log("touchstart") | |
document.addEventListener("touchmove", (e) => { | |
e.preventDefault(); | |
console.log("touchmove, should prevent") | |
}) | |
}) | |
</pre> | |
<h2>doesn't work</h2> | |
<pre> | |
document.addEventListener("touchstart", (e) => { | |
console.log("touchstart") | |
}) | |
setTimeout(() => { | |
document.addEventListener("touchmove", (e) => { | |
e.preventDefault(); | |
console.log("touchmove, should prevent") | |
}) | |
}, 0) | |
</pre> | |
<script> | |
//copypaste cases from above to test here | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment