Added button to scroll back to the top

This commit is contained in:
Florian SYLVAIN
2022-01-08 15:17:22 +01:00
parent 64a245fc1d
commit 730e2a2b3a
3 changed files with 49 additions and 2 deletions
+16
View File
@@ -308,6 +308,10 @@ function updateFilter(f) {
document.querySelector('#f-' + queryOption).style.boxShadow = 'inset rgba(0, 0, 0, 0.40) 0 0 5px'
}
function scrollTop() {
window.scrollTo({top: 0, behavior: 'smooth'});
}
document.addEventListener('click', e => {
if (e.target.id !== 'suggestions' && e.target !== searchBar && e.target !== searchBarButton) {
@@ -347,6 +351,10 @@ document.addEventListener('click', e => {
if (e.target.id.toString().includes('f-')) {
updateFilter(e.target.id)
}
if (e.target.classList.contains('scroll-to-top')) {
scrollTop()
}
}
})
@@ -359,6 +367,14 @@ navbarForm.addEventListener('submit', e => {
submitForm(0)
})
document.addEventListener('scroll', e => {
if (window.scrollY != 0) {
document.querySelector('#scrollToTop').style.display = 'block'
} else {
document.querySelector('#scrollToTop').style.display = 'none'
}
})
let urlSearch = urlParams.get('search')
let urlOption = urlParams.get('option')
let urlOffset = urlParams.get('offset')