diff options
| author | Aditya Telange <21258296+adityatelange@users.noreply.github.com> | 2021-03-25 11:00:22 +0530 |
|---|---|---|
| committer | Aditya Telange <21258296+adityatelange@users.noreply.github.com> | 2021-03-25 13:34:01 +0530 |
| commit | ddf004b709578a488a8c1c03478085460ba74cdd (patch) | |
| tree | 54ffd6f58d8af4a62650815a5b6bd3960488b3ed | |
| parent | a2b3be016947538ae60883db01a913865db38e0a (diff) | |
Allow disabling ScrollToTop button
- refactor corresponding code
usage =>
in site config:
params:
disableScrollToTop: true
closes: #321
| -rw-r--r-- | layouts/partials/footer.html | 18 |
1 files changed, 14 insertions, 4 deletions
diff --git a/layouts/partials/footer.html b/layouts/partials/footer.html index 49e6061..f818e85 100644 --- a/layouts/partials/footer.html +++ b/layouts/partials/footer.html @@ -9,6 +9,7 @@ <span>·</span> <span>Theme <a href="https://git.io/hugopapermod" rel="noopener" target="_blank">PaperMod</a></span> </footer> +{{- if (not .Site.Params.disableScrollToTop) }} <a href="#top" aria-label="go to top" title="Go to Top (Alt + G)"> <button class="top-link" id="top-link" type="button" accesskey="g"> <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 12 6" fill="currentColor"> @@ -16,6 +17,7 @@ </svg> </button> </a> +{{- end }} {{- partial "extend_footer.html" . -}} {{- $isHLJSdisabled := (.Site.Params.assets.disableHLJS | default .Params.disableHLJS ) }} {{- if (and (eq .Kind "page") (ne .Layout "archives") (ne .Layout "search") (not $isHLJSdisabled)) }} @@ -34,6 +36,11 @@ document.getElementById('menu').scrollLeft = localStorage.getItem("menu-scroll-position"); } } + + function menu_on_scroll() { + localStorage.setItem("menu-scroll-position", document.getElementById('menu').scrollLeft); + } + document.querySelectorAll('a[href^="#"]').forEach(anchor => { anchor.addEventListener("click", function (e) { e.preventDefault(); @@ -52,6 +59,11 @@ } }); }); + +</script> + +{{- if (not .Site.Params.disableScrollToTop) }} +<script> var mybutton = document.getElementById("top-link"); window.onscroll = function () { if (document.body.scrollTop > 800 || document.documentElement.scrollTop > 800) { @@ -63,11 +75,9 @@ } }; - function menu_on_scroll() { - localStorage.setItem("menu-scroll-position", document.getElementById('menu').scrollLeft); - } - </script> +{{- end }} + {{- if (not .Site.Params.disableThemeToggle) }} <script> document.getElementById("theme-toggle").addEventListener("click", () => { |
