Skip to content

Instantly share code, notes, and snippets.

@DesignHhuang
Created September 28, 2023 10:50
Show Gist options
  • Save DesignHhuang/ad9a01b87b65e1c46c831b148890eebf to your computer and use it in GitHub Desktop.
Save DesignHhuang/ad9a01b87b65e1c46c831b148890eebf to your computer and use it in GitHub Desktop.
useScrollToBottom:使用滚动到底部
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