-
-
Save zz/1b15dc042ce7653e93d210699a0135cc to your computer and use it in GitHub Desktop.
Detect scrolling to the bottom of a div in Vue.js
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
<template> | |
<div class="wrapper"> | |
<div class="box" @scroll="handleScroll"> | |
<p>Your content here...</p> | |
</div> | |
<a href="#" v-if="hasScrolledToBottom">Show After Scrolling</a> | |
</div> | |
</template> | |
<script> | |
export default { | |
data() { | |
return { | |
hasScrolledToBottom: false | |
} | |
}, | |
methods: { | |
handleScroll: function(el) { | |
if((el.target.offsetHeight + el.target.scrollTop) >= el.target.scrollHeight) { | |
this.hasScrolledToBottom = true; | |
} | |
} | |
} | |
} | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment