Skip to content

Commit 5ee86bf

Browse files
committed
style: hide top banner when scroll
1 parent 33d27fe commit 5ee86bf

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

lires_web/src/components/common/Banner.vue

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,24 @@
5252
_currentDarkTheme.value = !_currentDarkTheme.value;
5353
}
5454
55+
const mainDiv = ref(null as HTMLDivElement | null);
56+
let lastScrollTop = 0;
57+
window.addEventListener('scroll', function() {
58+
const scrollTop = window.scrollY || document.documentElement.scrollTop;
59+
if (scrollTop > lastScrollTop) {
60+
// Scrolling down
61+
mainDiv.value!.classList.add('hidden');
62+
} else {
63+
// Scrolling up
64+
mainDiv.value!.classList.remove('hidden');
65+
}
66+
lastScrollTop = scrollTop;
67+
});
68+
5569
</script>
5670

5771
<template>
58-
<div class="main shadow">
72+
<div class="main-banner shadow" ref="mainDiv">
5973
<div class="button">
6074
<BannerIcon v-if="props.returnHome" :iconSrc="homeIcon" labelText="Home" shortcut="ctrl+h"
6175
@onClick="()=>{router.push('/')}" title="home"/>
@@ -77,7 +91,7 @@
7791
</template>
7892

7993
<style scoped>
80-
div.main{
94+
div.main-banner{
8195
position: fixed;
8296
top: 10px;
8397
left: 10px;
@@ -94,6 +108,10 @@
94108
font-size: small;
95109
height: 30px;
96110
z-index: 1;
111+
transition: top 0.25s ease-in-out;
112+
}
113+
div.main-banner.hidden{
114+
top: -30px;
97115
}
98116
div.button{
99117
display: flex;

0 commit comments

Comments
 (0)