diff options
author | WayJam So <imsuwj@gmail.com> | 2020-05-03 15:29:11 +0300 |
---|---|---|
committer | WayJam So <imsuwj@gmail.com> | 2020-05-03 15:29:11 +0300 |
commit | 4684fca2c8817b1baf2c2be7ff3993b2080a62a1 (patch) | |
tree | 67cc7ea378b02e21b0504ac8e4dcaa7a40b68ac7 /assets/js/main.js |
Initial
Diffstat (limited to 'assets/js/main.js')
-rw-r--r-- | assets/js/main.js | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/assets/js/main.js b/assets/js/main.js new file mode 100644 index 0000000..6503c3a --- /dev/null +++ b/assets/js/main.js @@ -0,0 +1,19 @@ +(function() { + const backToTopBtn = document.getElementById("back_to_top"); + + window.onscroll = function() { + scrollFunction(backToTopBtn); + }; +})(); + +function scrollFunction(btn) { + const pageOffset = + document.documentElement.scrollTop || document.body.scrollTop; + if (btn) btn.style.visibility = pageOffset > 450 ? "visible" : "hidden"; +} + +// When the user clicks on the button, scroll to the top of the document +function backToTop() { + document.body.scrollTop = 0; // For Safari + document.documentElement.scrollTop = 0; // For Chrome, Firefox, IE and Opera +} |