Created
September 28, 2023 10:50
-
-
Save DesignHhuang/ad9a01b87b65e1c46c831b148890eebf to your computer and use it in GitHub Desktop.
useScrollToBottom:使用滚动到底部
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
import { onMounted, onUnmounted } from 'vue'; | |
export const useScrollToBottom = (callback = () => { }) => { | |
const handleScrolling = () => { | |
if ((window.innerHeight + window.scrollY) >= document.body.scrollHeight) { | |
callback(); | |
} | |
} | |
onMounted(() => { | |
window.addEventListener('scroll', handleScrolling); | |
}); | |
onUnmounted(() => { | |
window.removeEventListener('scroll', handleScrolling); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment