diff options
author | WayJam So <imsuwj@gmail.com> | 2020-05-11 04:50:05 +0300 |
---|---|---|
committer | WayJam So <imsuwj@gmail.com> | 2020-05-11 04:50:05 +0300 |
commit | 3e5ac3a4216a9ce4640d7cfc0c87742c848cccdf (patch) | |
tree | 086ef423eeb830171e1c278d788141b21d28e463 /assets | |
parent | 4dd22c357cc64c3fea09eeda6e9c4e5fb9c26c6d (diff) |
fix: to the top function binding
Diffstat (limited to 'assets')
-rw-r--r-- | assets/js/main.js | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/assets/js/main.js b/assets/js/main.js index 6503c3a..2b467a7 100644 --- a/assets/js/main.js +++ b/assets/js/main.js @@ -4,6 +4,8 @@ window.onscroll = function() { scrollFunction(backToTopBtn); }; + + backToTopBtn.addEventListener("click", backToTop) })(); function scrollFunction(btn) { @@ -13,7 +15,8 @@ function scrollFunction(btn) { } // When the user clicks on the button, scroll to the top of the document -function backToTop() { +function backToTop(e) { + e.preventDefault() document.body.scrollTop = 0; // For Safari document.documentElement.scrollTop = 0; // For Chrome, Firefox, IE and Opera } |