Skip to content

Instantly share code, notes, and snippets.

@aschmelyun
Created May 29, 2018 09:19
Show Gist options
  • Save aschmelyun/c4130e39479629e35ea40e4223be11b0 to your computer and use it in GitHub Desktop.
Save aschmelyun/c4130e39479629e35ea40e4223be11b0 to your computer and use it in GitHub Desktop.
Detect scrolling to the bottom of a div in Vue.js
<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.srcElement.offsetHeight + el.srcElement.scrollTop) >= el.srcElement.scrollHeight) {
this.hasScrolledToBottom = true;
}
}
}
}
</script>
@dmitry-udod
Copy link

Please, don't use srcElement -- it's deprecated. Use target instead.

Nice catch!

@Miltonbhowmick
Copy link

Please use Math.ceil() like below.
if(Math.ceil(el.srcElement.offsetHeight + el.srcElement.scrollTop)) >= el.srcElement.scrollHeight){..}

@MDileg
Copy link

MDileg commented May 13, 2023

It is not working, who knows when scroll bottom fetching data

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment