diff --git a/_includes/back-to-top.html b/_includes/back-to-top.html new file mode 100644 index 0000000..08dc201 --- /dev/null +++ b/_includes/back-to-top.html @@ -0,0 +1 @@ +
back-to-top
diff --git a/_layouts/default.html b/_layouts/default.html index 4ef991b..1591b89 100644 --- a/_layouts/default.html +++ b/_layouts/default.html @@ -32,6 +32,7 @@ {% include header.html headerClass='header-extra' %} {{content}} + {% include back-to-top.html %} {% include footer.html %} {% include sub-footer.html %} diff --git a/_sass/components/_back-to-top.scss b/_sass/components/_back-to-top.scss new file mode 100644 index 0000000..62fb018 --- /dev/null +++ b/_sass/components/_back-to-top.scss @@ -0,0 +1,15 @@ +#back-to-top { + display: none; + position: sticky; + bottom: 30px; + margin-bottom: 10px; + margin-right: 10px; + place-self: end; + padding: 10px; + z-index: 999; +} + +#back-to-top img{ + width: 3em; + height: 3em; +} \ No newline at end of file diff --git a/assets/css/style.scss b/assets/css/style.scss index 3160ad7..e3e3817 100644 --- a/assets/css/style.scss +++ b/assets/css/style.scss @@ -57,6 +57,7 @@ $sub-footer-text-color: $white; @import "components/strip"; @import "components/feature"; @import "components/social"; +@import "components/back-to-top"; // @import "components/fonts"; // Uncomment this line to self host font // Pages diff --git a/assets/js/scripts.js b/assets/js/scripts.js index 230e8ff..f7abdaa 100644 --- a/assets/js/scripts.js +++ b/assets/js/scripts.js @@ -35,3 +35,16 @@ for (i = 0; i < acc.length; i++) { } } +var backToTopBtn = document.querySelector("#back-to-top"); + +window.addEventListener("scroll", showArrowBtn); + +function showArrowBtn() { + if (document.body.scrollTop > 20 || document.documentElement.scrollTop > 20) { + backToTopBtn.style.display = "block"; + } else { + backToTopBtn.style.display = "none"; + } +} + +backToTopBtn.addEventListener("click", () => window.scrollTo({ top: 0, behavior: 'smooth' })); diff --git a/images/up-arrow.svg b/images/up-arrow.svg new file mode 100644 index 0000000..845ebd7 --- /dev/null +++ b/images/up-arrow.svg @@ -0,0 +1,18 @@ + + + + + + + + + + + + \ No newline at end of file