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 | |
parent | 4dd22c357cc64c3fea09eeda6e9c4e5fb9c26c6d (diff) |
fix: to the top function binding
-rw-r--r-- | assets/js/main.js | 5 | ||||
-rw-r--r-- | layouts/partials/backtotop.html | 2 |
2 files changed, 5 insertions, 2 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 } diff --git a/layouts/partials/backtotop.html b/layouts/partials/backtotop.html index 56dad23..906cc9e 100644 --- a/layouts/partials/backtotop.html +++ b/layouts/partials/backtotop.html @@ -1,4 +1,4 @@ -<a id="back_to_top" onclick="backToTop"> +<a id="back_to_top" title="Go To Top" href="#"> <span> <svg viewBox="0 0 24 24"> <path fill="none" d="M0 0h24v24H0z"></path> |