|
-
- export function useScrollEnd() {
- let callback = null
-
- const handleScroll = () => {
- const scrollPosition = window.innerHeight + window.scrollY
- const pageHeight = document.documentElement.offsetHeight - 1 // 1 pixel offset to fix mobile browser
-
- if (scrollPosition >= pageHeight && typeof callback === 'function') {
- callback()
- }
- }
-
- const onScrollEnd = (cb) => {
- callback = cb
- }
-
- onMounted(() => {
- window.addEventListener('scroll', handleScroll)
- })
-
- onUnmounted(() => {
- window.removeEventListener('scroll', handleScroll)
- })
-
- return { onScrollEnd }
- }
|