diff options
author | Henk Verlinde <henk@ventizo.com> | 2022-06-21 21:52:44 +0300 |
---|---|---|
committer | Henk Verlinde <henk@ventizo.com> | 2022-06-21 21:52:44 +0300 |
commit | dd6f7b578b9073f363d41f0e5575767226528f57 (patch) | |
tree | 12a067e278929eafd26e4844a92ca6a832e9d883 | |
parent | 75d250b240fe75249cc5682362c3a964761a6473 (diff) |
feat: add to top button as an option
-rw-r--r-- | assets/js/to-top.js | 20 | ||||
-rw-r--r-- | config/_default/params.toml | 1 | ||||
-rw-r--r-- | layouts/_default/baseof.html | 5 | ||||
-rw-r--r-- | layouts/partials/footer/script-footer.html | 6 |
4 files changed, 32 insertions, 0 deletions
diff --git a/assets/js/to-top.js b/assets/js/to-top.js new file mode 100644 index 0000000..3287f43 --- /dev/null +++ b/assets/js/to-top.js @@ -0,0 +1,20 @@ +var topbutton = document.getElementById('toTop'); + +if (topbutton !== null) { + + topbutton.style.display = 'none'; + window.onscroll = function() { + scrollFunction() + }; + +} + +function scrollFunction() { + + if (document.body.scrollTop > 40 || document.documentElement.scrollTop > 40) { + topbutton.style.display = 'block'; + } else { + topbutton.style.display = 'none'; + } + +} diff --git a/config/_default/params.toml b/config/_default/params.toml index 5780d96..f241b10 100644 --- a/config/_default/params.toml +++ b/config/_default/params.toml @@ -92,6 +92,7 @@ lastMod = false docsVersioning = false fullWidth = false navbarSticky = true + toTopButton = true [menu] [menu.section] diff --git a/layouts/_default/baseof.html b/layouts/_default/baseof.html index b8b4273..561b8e2 100644 --- a/layouts/_default/baseof.html +++ b/layouts/_default/baseof.html @@ -23,5 +23,10 @@ {{ block "sidebar-footer" . }}{{ end }} {{ partial "footer/footer.html" . }} {{ partial "footer/script-footer.html" . }} + {{ if eq .Site.Params.options.toTopButton true -}} + <div class="d-flex fixed-bottom pb-3 pb-lg-5 pe-3 pe-lg-5"> + <a id="toTop" href="#" class="btn btn-outline-primary rounded-circle ms-auto p-2"><span class="visually-hidden">Top</span><svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-chevron-up"><polyline points="18 15 12 9 6 15"></polyline></svg></a> + </div> + {{ end }} </body> </html>
\ No newline at end of file diff --git a/layouts/partials/footer/script-footer.html b/layouts/partials/footer/script-footer.html index f57261a..cc77b65 100644 --- a/layouts/partials/footer/script-footer.html +++ b/layouts/partials/footer/script-footer.html @@ -60,6 +60,12 @@ {{ $scrollLock := resources.Get "js/scroll-lock.js" | js.Build -}} {{ $slice = $slice | append $scrollLock -}} +{{ if .Site.Params.options.toTopButton -}} + {{ $toTopButton := resources.Get "js/to-top.js" -}} + {{ $toTopButton := $toTopButton | js.Build -}} + {{ $slice = $slice | append $toTopButton -}} +{{ end -}} + {{ $js := $slice | resources.Concat "main.js" -}} {{ if eq (hugo.Environment) "development" -}} |