Created
October 29, 2019 13:05
-
-
Save renankof/e9fe0908602d299d671131fdd05708b7 to your computer and use it in GitHub Desktop.
Inifity Scroll for vue
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
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