feat(overview): stop scroll of the sidebar when the bottom is reached

This commit is contained in:
Valentin Kaelin 2020-03-19 23:07:12 +01:00
parent 461b268661
commit 788f733c96

View file

@ -1,11 +1,11 @@
<template> <template>
<div v-if="overviewLoaded" key="overview" class="mt-3 flex text-center"> <div v-if="overviewLoaded" key="overview" class="mt-3 relative flex items-start text-center">
<div class="w-3/12"> <div ref="sidebar" :class="{'fixed fixed-sidebar': fixedSidebar}" class="sidebar">
<SummonerChampions /> <SummonerChampions />
<SummonerStats /> <SummonerStats />
<SummonerMates /> <SummonerMates />
</div> </div>
<div class="w-9/12"> <div :class="{'pushed-container': fixedSidebar}" class="w-9/12">
<div v-if="current && current.participants" class="mb-4"> <div v-if="current && current.participants" class="mb-4">
<LiveMatch /> <LiveMatch />
</div> </div>
@ -54,6 +54,16 @@ export default {
SummonerStats, SummonerStats,
}, },
data() {
return {
fixedSidebar: false,
sidebarRectangle: {
y: 354,
height: null,
},
}
},
computed: { computed: {
...mapState({ ...mapState({
current: state => state.summoner.live.match, current: state => state.summoner.live.match,
@ -64,7 +74,7 @@ export default {
watch: { watch: {
overviewLoaded() { overviewLoaded() {
this.fetchData() this.getSidebarHeight()
}, },
summonerFound() { summonerFound() {
this.fetchData() this.fetchData()
@ -73,6 +83,15 @@ export default {
created() { created() {
this.fetchData() this.fetchData()
window.addEventListener('scroll', this.handleScroll)
},
mounted() {
this.getSidebarHeight()
},
destroyed() {
window.removeEventListener('scroll', this.handleScroll)
}, },
methods: { methods: {
@ -81,7 +100,30 @@ export default {
this.overviewRequest() this.overviewRequest()
} }
}, },
getSidebarHeight() {
this.$nextTick(() => {
this.sidebarRectangle.height = this.$refs.sidebar ? this.$refs.sidebar.getBoundingClientRect().height : null
})
},
handleScroll() {
if (!this.sidebarRectangle.height) return
this.fixedSidebar = window.innerHeight + document.documentElement.scrollTop > this.sidebarRectangle.y + this.sidebarRectangle.height + 112
},
...mapActions('summoner', ['moreMatches', 'overviewRequest']), ...mapActions('summoner', ['moreMatches', 'overviewRequest']),
}, },
} }
</script> </script>
<style scoped>
.sidebar {
width: 300px;
}
.fixed-sidebar {
bottom: 112px;
}
.pushed-container {
margin-left: 300px;
}
</style>