Newer
Older
<template>
<div
class="header bg-white w-full fixed z-20 top-0 transition-transform duration-300 transform translate-y-0 dark:bg-black dark:text-gray-300"
:class="{ '-translate-y-20': scrolled }"
>
<nav class="container flex justify-between items-center mx-auto h-16">
<LayoutHeaderLogo />
<div class="flex justify-end items-center relative">
<LayoutHeaderMenu />
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
<LayoutHeaderMenuAvatar />
</div>
</nav>
</div>
</template>
<script>
export default {
name: 'LayoutHeader',
data() {
return {
limitPosition: 64,
scrolled: false,
lastPosition: 0,
}
},
mounted() {
window.addEventListener('scroll', this.handleScroll)
},
destroyed() {
window.removeEventListener('scroll', this.handleScroll)
},
methods: {
handleScroll() {
if (
this.lastPosition < window.scrollY &&
this.limitPosition < window.scrollY
) {
this.scrolled = true
// move up!
}
if (this.lastPosition > window.scrollY) {
this.scrolled = false
// move down
}
this.lastPosition = window.scrollY
// this.scrolled = window.scrollY > 250;
},
},
}
</script>
<style lang="postcss" scoped>
.header {
/* Copied from discourse */
box-shadow: 0 2px 4px -1px rgb(0 0 0 / 25%);
}
.menu-hamburger {
display: block;
fill: none;
height: 16px;
width: 16px;
stroke: currentcolor;
stroke-width: 3;
overflow: visible;
}
</style>