diff options
author | Darshan Baral <darshanbaral@gmail.com> | 2020-06-06 07:49:22 +0300 |
---|---|---|
committer | Darshan Baral <darshanbaral@gmail.com> | 2020-06-06 07:49:22 +0300 |
commit | 734cae246646cf1d761cf4edfcb346dedaee827f (patch) | |
tree | 5f206835c2a2505ac6102713ee815d8469667ca9 | |
parent | 212f21c524b92e7af9d72b06b008e5aafcd93b3d (diff) |
smooth scroll without js
-rw-r--r-- | layouts/partials/sidebar.html | 7 | ||||
-rw-r--r-- | static/js/myFunctions.js | 27 |
2 files changed, 14 insertions, 20 deletions
diff --git a/layouts/partials/sidebar.html b/layouts/partials/sidebar.html index 9f2ea79..23bfa3f 100644 --- a/layouts/partials/sidebar.html +++ b/layouts/partials/sidebar.html @@ -2,13 +2,12 @@ {{ if eq .Kind "page" }} {{ partial "prevnext" . }} {{ end }} - <p class="mb-1 mt-1 text-left"> + <a href="#" class="mb-1 mt-1 text-left"> <i class="nav-menu fas fa-chevron-circle-up" - title="Scroll to top" - onclick="scrollToTop()" + aria-label="Scroll to top" ></i> - </p> + </a> <p class="mb-1 mt-1 text-left"> <i title="Copy URL to share" diff --git a/static/js/myFunctions.js b/static/js/myFunctions.js index 82d4804..4e9c671 100644 --- a/static/js/myFunctions.js +++ b/static/js/myFunctions.js @@ -1,32 +1,27 @@ -window.onclick = function(event) {
+window.onclick = function (event) {
checkClick(event);
};
-window.ontouchstart = function(event) {
+window.ontouchstart = function (event) {
checkClick(event);
};
-checkClick = function(event) {
+checkClick = function (event) {
let insideMenu = false;
- Array.from(document.querySelectorAll(".show")).forEach(menu => {
+ Array.from(document.querySelectorAll(".show")).forEach((menu) => {
insideMenu = insideMenu || menu.contains(event.target);
});
if (!insideMenu && !event.target.matches(".hover-menu")) {
- Array.from(document.querySelectorAll(".hover-menu")).forEach(hovermenu => {
- hovermenu.nextElementSibling.style.maxHeight = "0px";
- });
+ Array.from(document.querySelectorAll(".hover-menu")).forEach(
+ (hovermenu) => {
+ hovermenu.nextElementSibling.style.maxHeight = "0px";
+ }
+ );
}
};
-let expandMenu = function(x) {
- Array.from(document.querySelectorAll(".hover-menu")).forEach(hovermenu => {
+let expandMenu = function (x) {
+ Array.from(document.querySelectorAll(".hover-menu")).forEach((hovermenu) => {
hovermenu.nextElementSibling.style.maxHeight = "0px";
});
let thisMenu = x.nextElementSibling;
thisMenu.style.maxHeight = thisMenu.scrollHeight + "px";
};
-let scrollToTop = () => {
- const c = document.documentElement.scrollTop || document.body.scrollTop;
- if (c > 0) {
- window.requestAnimationFrame(scrollToTop);
- window.scrollTo(0, c - c / 8);
- }
-};
\ No newline at end of file |