Last active
May 17, 2017 13:04
-
-
Save guidobouman/7651ed5a7fdddb1b91323fa8cc5a08c1 to your computer and use it in GitHub Desktop.
Vue app that moves it's scrolling into a child div. In case you ever need to create a web app.
This file contains hidden or 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
<template> | |
<div id="app" @touchmove.prevent> | |
<header-bar></header-bar> | |
<main @touchmove="enforceScroll"> | |
<router-view></router-view> | |
</main> | |
<footer-bar></footer-bar> | |
</div> | |
</template> | |
<script> | |
import HeaderBar from '@/components/HeaderBar'; | |
import FooterBar from '@/components/FooterBar'; | |
export default { | |
components: { HeaderBar, FooterBar }, | |
name: 'app', | |
methods: { | |
enforceScroll(event) { | |
const element = event.currentTarget; | |
const availableScroll = element.scrollHeight - element.offsetHeight; | |
const scrolled = element.scrollTop; | |
if (availableScroll === 0) { | |
return; | |
} | |
event.stopPropagation(); | |
if (scrolled === 0) { | |
element.scrollTop = 1; | |
} else if (scrolled === availableScroll) { | |
element.scrollTop = scrolled - 1; | |
} | |
}, | |
}, | |
}; | |
</script> | |
<style lang="stylus"> | |
html, body { | |
height: 100%; | |
overflow: hidden; | |
} | |
#app { | |
height: 100%; | |
display: flex; | |
flex-direction: column; | |
> * { | |
flex: none; | |
} | |
} | |
main { | |
flex-grow: 1; | |
overflow: auto; | |
-webkit-overflow-scrolling: touch; | |
} | |
</style> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment