UNPKG

hexo-theme-redefine

Version:

Redefine your writing with Hexo Theme Redefine.

45 lines (37 loc) 829 B
let didInit = false; const backToTop = () => { window.scrollTo({ top: 0, behavior: "smooth", }); }; const backToBottom = () => { const docHeight = document.body.scrollHeight; window.scrollTo({ top: docHeight, behavior: "smooth", }); }; const handleClick = (event) => { const topButton = event.target.closest(".tool-scroll-to-top"); if (topButton) { backToTop(); return; } const bottomButton = event.target.closest(".tool-scroll-to-bottom"); if (bottomButton) { backToBottom(); } }; const initScrollTopBottom = ({ signal } = {}) => { if (didInit) { return; } didInit = true; if (signal) { document.addEventListener("click", handleClick, { signal }); } else { document.addEventListener("click", handleClick); } }; export default initScrollTopBottom;