Skip to content

Instantly share code, notes, and snippets.

@guidobouman
Last active May 17, 2017 13:04
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 guidobouman/7651ed5a7fdddb1b91323fa8cc5a08c1 to your computer and use it in GitHub Desktop.
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.
<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