Skip to content

Instantly share code, notes, and snippets.

@renankof
Created October 29, 2019 13:05
Show Gist options
  • Save renankof/e9fe0908602d299d671131fdd05708b7 to your computer and use it in GitHub Desktop.
Save renankof/e9fe0908602d299d671131fdd05708b7 to your computer and use it in GitHub Desktop.
Inifity Scroll for vue
getDistFromBottom() {
const scrollPosition = window.pageYOffset;
const windowSize = window.innerHeight;
const bodyHeight = document.getElementById('deals-page').offsetHeight;
return Math.max(bodyHeight - (scrollPosition + windowSize), 0);
},
scroll() {
window.onscroll = () => {
if (!this.nextPage) return;
const valueToScrool = window.innerHeight / 4;
const distToBottom = this.getDistFromBottom();
if (distToBottom > 0 && distToBottom <= (valueToScrool) && !this.loading) {
this.getData(true, this.nextPage);
}
};
},
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment