File tree Expand file tree Collapse file tree 13 files changed +126
-43
lines changed Expand file tree Collapse file tree 13 files changed +126
-43
lines changed Original file line number Diff line number Diff line change 103
103
isDark . addListener ( toggleDarkMode ) ;
104
104
105
105
} ) ( ) ;
106
+
107
+ // Hide/show header on scroll
108
+
109
+ ( function ( document , window ) {
110
+ 'use strict' ;
111
+
112
+ var element = document . getElementById ( 'dynamic-header' ) ;
113
+
114
+ if ( ! element ) {
115
+ return true ;
116
+ }
117
+
118
+ var elHeight = 0 ,
119
+ elTop = 0 ,
120
+ dHeight = 0 ,
121
+ wHeight = 0 ,
122
+ wScrollCurrent = 0 ,
123
+ wScrollBefore = 0 ,
124
+ wScrollDiff = 0 ;
125
+
126
+ window . addEventListener ( 'scroll' , function ( ) {
127
+ elHeight = element . offsetHeight ;
128
+ dHeight = document . body . offsetHeight ;
129
+ wHeight = window . innerHeight ;
130
+ wScrollCurrent = window . pageYOffset ;
131
+ wScrollDiff = wScrollBefore - wScrollCurrent ;
132
+ elTop = parseInt ( window . getComputedStyle ( element ) . getPropertyValue ( 'top' ) ) + wScrollDiff ;
133
+
134
+ if ( wScrollCurrent <= 0 ) {
135
+ element . style . top = '0px' ;
136
+ } else if ( wScrollDiff > 0 ) {
137
+ element . style . top = ( elTop > 0 ? 0 : elTop ) + 'px' ;
138
+ } else if ( wScrollDiff < 0 ) {
139
+ if ( wScrollCurrent + wHeight >= dHeight - elHeight ) {
140
+ element . style . top = ( ( elTop = wScrollCurrent + wHeight - dHeight ) < 0 ? elTop : 0 ) + 'px' ;
141
+ } else {
142
+ element . style . top = ( Math . abs ( elTop ) > elHeight ? - elHeight : elTop ) + 'px' ;
143
+ }
144
+ }
145
+
146
+ wScrollBefore = wScrollCurrent ;
147
+ } ) ;
148
+
149
+ } ( document , window , 0 ) ) ;
Original file line number Diff line number Diff line change 12
12
margin : 0 ; /* 1 */
13
13
background-color : $color-text ;
14
14
color : $color-text-white-out ;
15
- scroll-behavior : smooth ; // https://caniuse.com/#search=scroll-behavior
15
+ scroll-behavior : smooth ;
16
+ scroll-padding-top : 1rem ;
16
17
}
17
18
18
19
@include dark-mode {
@@ -85,9 +86,8 @@ noscript {
85
86
*/
86
87
87
88
.wrapper {
88
- position : relative ;
89
- padding-top : 1px ;
90
- border-bottom : 1px solid $color-background ;
89
+ margin : -1px 0 ;
90
+ padding : 1px 0 ;
91
91
background : $color-background ;
92
92
color : $color-text ;
93
93
}
@@ -100,6 +100,39 @@ noscript {
100
100
}
101
101
}
102
102
103
+ /* *
104
+ * Show/hide header on scroll.
105
+ *
106
+ * Example HTML:
107
+ *
108
+ * <div id="dynamic-header">
109
+ * <header>
110
+ * <nav>
111
+ * </div>
112
+ */
113
+
114
+ #dynamic-header {
115
+ border-bottom : 2px solid $color-text ;
116
+ background : $color-background ;
117
+ color : $color-text ;
118
+
119
+ .js & {
120
+ position : sticky ;
121
+ z-index : 100 ;
122
+ top : 0 ;
123
+ right : 0 ;
124
+ width : 100% ;
125
+ }
126
+ }
127
+
128
+ @include dark-mode {
129
+ #dynamic-header {
130
+ border-bottom-color : $dark-color-border-extra-dark ;
131
+ background : $dark-color-background ;
132
+ color : $dark-color-text ;
133
+ }
134
+ }
135
+
103
136
/* *
104
137
* Outer wrapper for footer.
105
138
*
@@ -114,6 +147,13 @@ noscript {
114
147
.wrapper-footer {
115
148
flex : 1 ;
116
149
padding-bottom : 0.5em ;
150
+ border-top : 1px solid $color-background ;
151
+ }
152
+
153
+ @include dark-mode {
154
+ .wrapper-footer {
155
+ border-top-color : $dark-color-border-extra-dark ;
156
+ }
117
157
}
118
158
119
159
/* *
@@ -145,7 +185,7 @@ noscript {
145
185
}
146
186
147
187
.masthead {
148
- margin : 1 em 0 ;
188
+ margin : 0.75 em 0 ;
149
189
font-size : 1rem ;
150
190
151
191
a {
Original file line number Diff line number Diff line change 155
155
156
156
.a--skip-link {
157
157
position : absolute ;
158
- z-index : 2 ;
158
+ z-index : 101 ;
159
159
top : 1px ;
160
160
left : 1px ;
161
161
padding : 0.25em 0.5em ;
Original file line number Diff line number Diff line change 1
1
/* Navigation
2
2
========================================================================== */
3
3
4
- .nav-container {
5
- border-bottom : 2px solid $color-text ;
6
- }
7
-
8
- @include dark-mode {
9
- .nav-container {
10
- border-bottom-color : $dark-color-border-extra-dark ;
11
- }
12
- }
13
-
14
4
#site-navigation {
15
5
font-family : $font-serif ;
16
6
148
138
display : none ;
149
139
position : absolute ;
150
140
z-index : 2 ;
151
- top : 1 em ;
141
+ top : 0.75 rem ;
152
142
right : 5% ;
153
143
width : 32px ;
154
144
height : 32px ;
155
- margin-top : 1px ;
156
145
border : 1px solid $color-background ;
157
146
background-image : url (" data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 32 32'%3E%3Cpath fill='%23333' d='M4 6h24v4H4zm0 8h24v4H4zm0 8h24v4H4z'/%3E%3C/svg%3E" );
158
147
background-size : 32px 32px ;
Original file line number Diff line number Diff line change 128
128
129
129
< a class ="a--skip-link " href ="#main "> Go to main content</ a >
130
130
131
- < div class ="wrapper ">
132
-
131
+ < div id ="dynamic-header ">
133
132
134
133
<!-- Header -->
135
134
< header class ="site-header " itemscope itemtype ="https://schema.org/Organization ">
@@ -147,7 +146,6 @@ <h1 class="masthead" itemprop="name"><a rel="home" itemprop="url" href="https://
147
146
</ div >
148
147
</ header >
149
148
150
-
151
149
<!-- Navigation -->
152
150
< div class ="nav-container ">
153
151
< a id ="site-navigation-toggle " href ="# " role ="button " aria-controls ="site-navigation " title ="Navigation menu "> Navigation menu</ a >
@@ -164,6 +162,9 @@ <h1 class="masthead" itemprop="name"><a rel="home" itemprop="url" href="https://
164
162
</ nav >
165
163
</ div >
166
164
165
+ </ div > <!-- /#dynamic-header -->
166
+
167
+ < div class ="wrapper ">
167
168
168
169
<!-- Primary Content -->
169
170
< main id ="main " aria-label ="Main content " itemscope itemtype ="https://schema.org/Blog ">
Original file line number Diff line number Diff line change 78
78
79
79
< a class ="a--skip-link " href ="#main "> Go to main content</ a >
80
80
81
- < div class ="wrapper ">
82
-
81
+ < div id ="dynamic-header ">
83
82
84
83
<!-- Header -->
85
84
< header class ="site-header " itemscope itemtype ="https://schema.org/Organization ">
@@ -97,7 +96,6 @@ <h1 class="masthead" itemprop="name"><a rel="home" itemprop="url" href="https://
97
96
</ div >
98
97
</ header >
99
98
100
-
101
99
<!-- Navigation -->
102
100
< div class ="nav-container ">
103
101
< a id ="site-navigation-toggle " href ="# " role ="button " aria-controls ="site-navigation " title ="Navigation menu "> Navigation menu</ a >
@@ -114,6 +112,9 @@ <h1 class="masthead" itemprop="name"><a rel="home" itemprop="url" href="https://
114
112
</ nav >
115
113
</ div >
116
114
115
+ </ div > <!-- /#dynamic-header -->
116
+
117
+ < div class ="wrapper ">
117
118
118
119
<!-- Primary Content -->
119
120
< main id ="main " aria-label ="Main content " itemscope itemtype ="https://schema.org/Blog ">
Original file line number Diff line number Diff line change 49
49
50
50
< a class ="a--skip-link " href ="#main "> Go to main content</ a >
51
51
52
- < div class ="wrapper ">
53
-
52
+ < div id ="dynamic-header ">
54
53
55
54
<!-- Header -->
56
55
< header class ="site-header " itemscope itemtype ="https://schema.org/Organization ">
@@ -68,7 +67,6 @@ <h1 class="masthead" itemprop="name"><a rel="home" itemprop="url" href="https://
68
67
</ div >
69
68
</ header >
70
69
71
-
72
70
<!-- Navigation -->
73
71
< div class ="nav-container ">
74
72
< a id ="site-navigation-toggle " href ="# " role ="button " aria-controls ="site-navigation " title ="Navigation menu "> Navigation menu</ a >
@@ -85,6 +83,9 @@ <h1 class="masthead" itemprop="name"><a rel="home" itemprop="url" href="https://
85
83
</ nav >
86
84
</ div >
87
85
86
+ </ div > <!-- /#dynamic-header -->
87
+
88
+ < div class ="wrapper ">
88
89
89
90
<!-- Primary Content -->
90
91
< main id ="main " aria-label ="Main content ">
Original file line number Diff line number Diff line change 28
28
29
29
< a class ="a--skip-link " href ="#main "> Go to main content</ a >
30
30
31
- < div class ="wrapper ">
32
-
31
+ < div id ="dynamic-header ">
33
32
34
33
<!-- Header -->
35
34
< header class ="site-header " itemscope itemtype ="https://schema.org/Organization ">
@@ -47,7 +46,6 @@ <h1 class="masthead" itemprop="name"><a rel="home" itemprop="url" href="https://
47
46
</ div >
48
47
</ header >
49
48
50
-
51
49
<!-- Navigation -->
52
50
< div class ="nav-container ">
53
51
< a id ="site-navigation-toggle " href ="# " role ="button " aria-controls ="site-navigation " title ="Navigation menu "> Navigation menu</ a >
@@ -64,6 +62,9 @@ <h1 class="masthead" itemprop="name"><a rel="home" itemprop="url" href="https://
64
62
</ nav >
65
63
</ div >
66
64
65
+ </ div > <!-- /#dynamic-header -->
66
+
67
+ < div class ="wrapper ">
67
68
68
69
<!-- Primary Content -->
69
70
< main id ="main " aria-label ="Main content ">
Original file line number Diff line number Diff line change 72
72
73
73
< a class ="a--skip-link " href ="#main "> Go to main content</ a >
74
74
75
- < div class ="wrapper ">
76
-
75
+ < div id ="dynamic-header ">
77
76
78
77
<!-- Header -->
79
78
< header class ="site-header " itemscope itemtype ="https://schema.org/Organization ">
@@ -91,7 +90,6 @@ <h1 class="masthead" itemprop="name"><a rel="home" itemprop="url" href="https://
91
90
</ div >
92
91
</ header >
93
92
94
-
95
93
<!-- Navigation -->
96
94
< div class ="nav-container ">
97
95
< a id ="site-navigation-toggle " href ="# " role ="button " aria-controls ="site-navigation " title ="Navigation menu "> Navigation menu</ a >
@@ -108,6 +106,9 @@ <h1 class="masthead" itemprop="name"><a rel="home" itemprop="url" href="https://
108
106
</ nav >
109
107
</ div >
110
108
109
+ </ div > <!-- /#dynamic-header -->
110
+
111
+ < div class ="wrapper ">
111
112
112
113
<!-- Primary Content -->
113
114
< main id ="main " aria-label ="Main content ">
Original file line number Diff line number Diff line change 63
63
64
64
< a class ="a--skip-link " href ="#main "> Go to main content</ a >
65
65
66
- < div class ="wrapper ">
67
-
66
+ < div id ="dynamic-header ">
68
67
69
68
<!-- Header -->
70
69
< header class ="site-header " itemscope itemtype ="https://schema.org/Organization ">
@@ -82,7 +81,6 @@ <h1 class="masthead" itemprop="name"><a rel="home" itemprop="url" href="https://
82
81
</ div >
83
82
</ header >
84
83
85
-
86
84
<!-- Navigation -->
87
85
< div class ="nav-container ">
88
86
< a id ="site-navigation-toggle " href ="# " role ="button " aria-controls ="site-navigation " title ="Navigation menu "> Navigation menu</ a >
@@ -99,6 +97,9 @@ <h1 class="masthead" itemprop="name"><a rel="home" itemprop="url" href="https://
99
97
</ nav >
100
98
</ div >
101
99
100
+ </ div > <!-- /#dynamic-header -->
101
+
102
+ < div class ="wrapper ">
102
103
103
104
<!-- Primary Content -->
104
105
< main aria-label ="Main content ">
You can’t perform that action at this time.
0 commit comments