feat: back to top scrolls back more gracefully

This commit is contained in:
grassblock 2025-05-18 19:52:35 +08:00
parent a95920db70
commit c56db7d692

View file

@ -21,7 +21,14 @@
// When the user clicks on the button, scroll to the top of the document
toTopButton.addEventListener("click", toTop);
function toTop() {
try {
// scrollback gracefully
window.scrollTo({top: 0, behavior: 'smooth'});
} catch (e) {
// if there is a error,return to top directly
console.error(e);
document.body.scrollTop = 0;
document.documentElement.scrollTop = 0;
}
}
</script>