feat: back to top scrolls back more gracefully
This commit is contained in:
parent
a95920db70
commit
c56db7d692
1 changed files with 9 additions and 2 deletions
|
@ -21,7 +21,14 @@
|
||||||
// When the user clicks on the button, scroll to the top of the document
|
// When the user clicks on the button, scroll to the top of the document
|
||||||
toTopButton.addEventListener("click", toTop);
|
toTopButton.addEventListener("click", toTop);
|
||||||
function 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.body.scrollTop = 0;
|
||||||
document.documentElement.scrollTop = 0;
|
document.documentElement.scrollTop = 0;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
</script>
|
</script>
|
Loading…
Add table
Add a link
Reference in a new issue