Skip to content

Commit

Permalink
Properly disable scrolling in Android 🤖
Browse files Browse the repository at this point in the history
iOS still bounces
  • Loading branch information
pirelenito committed Oct 28, 2018
1 parent 290f9b5 commit 25dcfaa
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 2 deletions.
1 change: 1 addition & 0 deletions public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
<meta charset="utf-8">
<link rel="shortcut icon" href="%PUBLIC_URL%/favicon.ico">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<meta name="apple-mobile-web-app-capable" content="yes"/>
<meta name="theme-color" content="#000000">
<!--
manifest.json provides metadata used when your web app is added to the
Expand Down
4 changes: 4 additions & 0 deletions src/Game.css
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,7 @@
text-align: center;
font-size: 4rem;
}

#game {
touch-action: none;
}
11 changes: 9 additions & 2 deletions src/Game.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,8 @@ export default class Game extends Component {
animate()

const handleMove = e => {
e.preventDefault()

const touch = e.touches ? e.touches[0] : e

this.player.acceleration.x =
Expand All @@ -128,8 +130,13 @@ export default class Game extends Component {
this.player.maxSpeed = (center.distanceTo(mouse) / center.distanceTo(corner)) * PLAYER_MAX_SPEED
}

window.addEventListener('touchmove', handleMove, false)
window.addEventListener('mousemove', handleMove, false)
const disableScroll = e => {
e.preventDefault()
}

window.addEventListener('touchstart', disableScroll)
window.addEventListener('touchmove', handleMove)
window.addEventListener('mousemove', handleMove)
}

render() {
Expand Down
1 change: 1 addition & 0 deletions src/index.css
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
html {
font-family: 'VT323', monospace;
font-size: 1vw;
overflow: hidden;
}

body {
Expand Down

0 comments on commit 25dcfaa

Please sign in to comment.