-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdemo.html
171 lines (165 loc) · 4.45 KB
/
demo.html
1
2
3
4
5
6
7
8
9
10
11
12
13
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width,initial-scale=1" />
<title>Hiding Header</title>
<style>
*,
*::before,
*::after {
box-sizing: border-box;
}
body {
margin: 0;
font-family: sans-serif;
}
button {
cursor: pointer;
}
.tracks {
display: flex;
min-height: 200vh;
}
.track {
flex-grow: 1;
background-color: rgb(191, 221, 255);
background-image: linear-gradient(white 2px, transparent 2px),
linear-gradient(90deg, white 2px, transparent 2px),
linear-gradient(rgba(255, 255, 255, 0.3) 1px, transparent 1px),
linear-gradient(90deg, rgba(255, 255, 255, 0.3) 1px, transparent 1px);
background-size: 100px 100px, 100px 100px, 20px 20px, 20px 20px;
background-position: center top;
}
.track:not(:last-child) {
border-right: 3px solid #000c27;
}
.headerContent {
display: flex;
justify-content: center;
align-items: center;
background-color: #000000;
color: #ffffff;
padding: 1em;
min-height: 4em;
}
.headerContent-2 {
min-height: 5em;
}
.headerContent-3 {
min-height: 6em;
}
.beforeContent {
height: 2em;
background-color: #858585dd;
}
.afterContent {
height: 8em;
background-color: #e2e2e2dd;
padding: 1em;
}
.otherContent {
height: 150vh;
border-top: 3px solid #000c27;
background-color: rgb(255, 227, 191);
background-image: linear-gradient(white 2px, transparent 2px),
linear-gradient(90deg, white 2px, transparent 2px),
linear-gradient(rgba(255, 255, 255, 0.3) 1px, transparent 1px),
linear-gradient(90deg, rgba(255, 255, 255, 0.3) 1px, transparent 1px);
background-size: 100px 100px, 100px 100px, 20px 20px, 20px 20px;
background-position: center top;
}
.actions {
position: fixed;
right: 0;
bottom: 0;
border: 0 solid black;
border-top-width: 1px;
border-left-width: 1px;
background-color: white;
padding: 0.5em;
}
.hidingHeader {
position: relative;
--hidingHeader-height: auto;
--hidingHeader-bounds-height: auto;
--hidingHeader-animation-offset: 0px;
z-index: 10;
height: var(--hidingHeader-bounds-height);
margin-bottom: calc(
var(--hidingHeader-height) - var(--hidingHeader-bounds-height)
);
pointer-events: none;
}
.hidingHeader-in {
position: relative;
position: sticky;
top: 0;
pointer-events: auto;
transition: transform 0.2s;
transform: translateY(var(--hidingHeader-animation-offset));
}
</style>
</head>
<body>
<div class="tracks">
<div class="track">
<div class="hidingHeader">
<div class="hidingHeader-in">
<div class="headerContent headerContent-1">Standard header</div>
</div>
</div>
<div class="afterContent">Other content<br />Scroll down and up</div>
</div>
<div class="track">
<div class="beforeContent"></div>
<div class="hidingHeader">
<div class="hidingHeader-in">
<div class="hidingHeader-content">
<div class="headerContent headerContent-2">Offset header</div>
</div>
</div>
</div>
<div class="afterContent">Other content</div>
</div>
<div class="track">
<div class="hidingHeader">
<div class="hidingHeader-in">
<div class="hidingHeader-content">
<div class="headerContent headerContent-3">
Uninitialized header
</div>
</div>
</div>
</div>
<div class="afterContent">Other content</div>
</div>
</div>
<div class="otherContent"></div>
<div class="actions">
<button type="button" class="js-reveal">Reveal</button>
<button type="button" class="js-hide">Hide</button>
</div>
<script type="module">
const revealButton = document.querySelector('.js-reveal')
const hideButton = document.querySelector('.js-hide')
import('./dist/index.es.js')
.catch((error) =>
import('https://unpkg.com/hiding-header@latest/dist/index.es.js')
)
.then((library) => {
const { hidingHeader } = library
const containers = document.querySelectorAll('.hidingHeader')
containers.forEach((container, i) => {
if (i === containers.length - 1) {
// Last uninitialized
return
}
const instance = hidingHeader(container)
revealButton.addEventListener('click', instance.reveal)
hideButton.addEventListener('click', instance.hide)
})
})
</script>
</body>
</html>