Client - add button to scroll to the top

This commit is contained in:
Sam 2021-09-29 20:16:04 +02:00
parent 98aa80788b
commit d9790e0465
4 changed files with 67 additions and 4 deletions

View File

@ -1,4 +1,5 @@
<template> <template>
<div id="top" />
<NavBar @menuInteraction="updateHideScrollBar" /> <NavBar @menuInteraction="updateHideScrollBar" />
<div v-if="appLoading" class="app-container"> <div v-if="appLoading" class="app-container">
<div class="app-loading"> <div class="app-loading">
@ -9,6 +10,15 @@
<router-view v-if="appConfig" /> <router-view v-if="appConfig" />
<NoConfig v-else /> <NoConfig v-else />
</div> </div>
<div class="container scroll">
<div
class="scroll-button"
:class="{ 'display-button': displayScrollButton }"
@click="scrollToTop"
>
<i class="fa fa-chevron-up" aria-hidden="true"></i>
</div>
</div>
<Footer /> <Footer />
</template> </template>
@ -34,6 +44,7 @@
defineComponent, defineComponent,
ref, ref,
onBeforeMount, onBeforeMount,
onMounted,
} from 'vue' } from 'vue'
import Loader from '@/components/Common/Loader.vue' import Loader from '@/components/Common/Loader.vue'
@ -77,19 +88,46 @@
() => store.getters[ROOT_STORE.GETTERS.APP_LOADING] () => store.getters[ROOT_STORE.GETTERS.APP_LOADING]
) )
const hideScrollBar = ref(false) const hideScrollBar = ref(false)
const displayScrollButton = ref(false)
onBeforeMount(() =>
store.dispatch(ROOT_STORE.ACTIONS.GET_APPLICATION_CONFIG)
)
onMounted(() => scroll())
function updateHideScrollBar(isMenuOpen: boolean) { function updateHideScrollBar(isMenuOpen: boolean) {
hideScrollBar.value = isMenuOpen hideScrollBar.value = isMenuOpen
} }
onBeforeMount(() => function isScrolledToBottom(element: Element): boolean {
store.dispatch(ROOT_STORE.ACTIONS.GET_APPLICATION_CONFIG) return (
) element.getBoundingClientRect().top < window.innerHeight &&
element.getBoundingClientRect().bottom >= 0
)
}
function scroll() {
window.onscroll = () => {
let bottom = document.querySelector('#bottom')
displayScrollButton.value =
bottom !== null && isScrolledToBottom(bottom)
}
}
function scrollToTop() {
window.scrollTo({
top: 0,
behavior: 'smooth',
})
setTimeout(() => {
displayScrollButton.value = false
}, 300)
}
return { return {
appConfig, appConfig,
appLoading, appLoading,
hideScrollBar, hideScrollBar,
displayScrollButton,
scrollToTop,
updateHideScrollBar, updateHideScrollBar,
} }
}, },
@ -111,4 +149,25 @@
height: 100%; height: 100%;
} }
} }
.scroll {
display: flex;
justify-content: flex-end;
position: fixed;
bottom: 42px;
right: -15px;
padding: 0 $default-padding * 2.5;
.scroll-button {
background-color: var(--scroll-button-bg-color);
border-radius: $border-radius;
box-shadow: 1px 1px 3px lightgrey;
display: none;
padding: 0 $default-padding;
&.display-button {
display: block;
}
}
}
</style> </style>

View File

@ -43,6 +43,8 @@
--disabled-background-color: #e0e0e0; --disabled-background-color: #e0e0e0;
--disabled-color: #a3a3a3; --disabled-color: #a3a3a3;
--scroll-button-bg-color: rgba(255, 255, 255, .7);
--workout-trophy-color: #daa520; --workout-trophy-color: #daa520;
--workout-img-color: invert(22%) sepia(25%) saturate(646%) hue-rotate(169deg) --workout-img-color: invert(22%) sepia(25%) saturate(646%) hue-rotate(169deg)
brightness(97%) contrast(96%); brightness(97%) contrast(96%);

View File

@ -63,6 +63,7 @@
/> />
</div> </div>
</div> </div>
<div id="bottom" />
</div> </div>
</template> </template>
@ -122,10 +123,10 @@
<style lang="scss" scoped> <style lang="scss" scoped>
@import '~@/scss/base'; @import '~@/scss/base';
#dashboard { #dashboard {
padding-bottom: 30px;
.dashboard-container { .dashboard-container {
display: flex; display: flex;
flex-direction: row; flex-direction: row;
padding-bottom: 30px;
.dashboard-sub-container { .dashboard-sub-container {
display: flex; display: flex;

View File

@ -27,6 +27,7 @@
v-if="!displaySegment" v-if="!displaySegment"
:notes="workoutData.workout.notes" :notes="workoutData.workout.notes"
/> />
<div id="bottom" />
</div> </div>
<div v-else> <div v-else>
<NotFound v-if="!workoutData.loading" target="WORKOUT" /> <NotFound v-if="!workoutData.loading" target="WORKOUT" />