Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add back to top button #269

Merged
merged 1 commit into from
Nov 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions ui/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import './bootstrap'
import RelativeTime from 'dayjs/plugin/relativeTime' // ES 2015
dayjs.extend(RelativeTime)

import './src/js/scroll-to-top'

// For node attribute table functionality
import 'bootstrap/js/dist/tab'

Expand Down
25 changes: 25 additions & 0 deletions ui/src/js/scroll-to-top.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

let scrollToTopBtn = document.getElementById("btn-scroll-to-top");
let fourViewports = window.innerHeight * 4;

window.onscroll = function () {
scrollFunction();
};

function scrollFunction() {
if (
document.body.scrollTop > fourViewports ||
document.documentElement.scrollTop > fourViewports
) {
scrollToTopBtn.style.display = "block";
} else {
scrollToTopBtn.style.display = "none";
}
}

scrollToTopBtn.addEventListener("click", backToTop);

function backToTop() {
document.body.scrollTop = 0;
document.documentElement.scrollTop = 0;
}
8 changes: 8 additions & 0 deletions ui/src/scss/custom.scss
Original file line number Diff line number Diff line change
Expand Up @@ -99,3 +99,11 @@ $color-mode-type: data;
border-right-color: var(--bs-tertiary-color);
}
}

#btn-scroll-to-top {
color: var(--bs-gray);
position: fixed;
bottom: 1rem;
right: 1rem;
display: none;
}
6 changes: 6 additions & 0 deletions ui/templates/layouts/footer.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,9 @@
</div>
</div>
</footer>
<button id="btn-scroll-to-top" class="btn border-0" aria-label="Back to Top">
<p class="m-lg-1"><svg xmlns="http://www.w3.org/2000/svg" width="32" height="32" fill="currentColor" class="bi bi-arrow-up-circle-fill" viewBox="0 0 16 16" focusable="false">
<path d="M16 8A8 8 0 1 0 0 8a8 8 0 0 0 16 0zm-7.5 3.5a.5.5 0 0 1-1 0V5.707L5.354 7.854a.5.5 0 1 1-.708-.708l3-3a.5.5 0 0 1 .708 0l3 3a.5.5 0 0 1-.708.708L8.5 5.707V11.5z"/>
</svg></p>
<span>Back to Top</span>
</button>