Skip to content

Commit 028f302

Browse files
authored
Remove navbar clone; instead render navbar using position: sticky (#358)
1 parent 5be50a4 commit 028f302

File tree

3 files changed

+6
-34
lines changed

3 files changed

+6
-34
lines changed

assets/js/shortcuts.js

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -22,26 +22,13 @@ function throttle(fn, interval) {
2222
};
2323
}
2424

25-
function scrollNavbar() {
26-
const scrollPosition = document.documentElement.scrollTop;
27-
28-
//Navbar Clone
29-
const navbarClone = document.getElementById("navbar-clone");
30-
31-
// Make navbar sticky, by activating a second, duplicate navbar
32-
// that is fixed to the top of the screen.
33-
navbarClone.classList.toggle("is-active", scrollPosition > 50);
34-
}
35-
3625
// Highlight currently scrolled to header in shortcuts
3726
// Based on https://stackoverflow.com/a/32396543/214686
3827
// and
3928
// https://stackoverflow.com/a/57494988/214686
4029
// which fixes some issues with the first, particularly
4130
// around scrolling upward.
42-
function scrollHeadersAndNavbar() {
43-
scrollNavbar();
44-
31+
function scrollHeaders() {
4532
const scrollPosition = document.documentElement.scrollTop;
4633
const headers = Array.from(
4734
document.querySelectorAll(":is(h1, h2, h3, h4, h5, h6)[id]"),
@@ -79,14 +66,14 @@ function scrollHeadersAndNavbar() {
7966
});
8067
}
8168

82-
const throttledScrollHeadersAndNavbar = throttle(scrollHeadersAndNavbar, 100);
69+
const throttledScrollHeaders = throttle(scrollHeaders, 100);
8370

8471
function bindScroll() {
85-
window.addEventListener("scroll", throttledScrollHeadersAndNavbar);
72+
window.addEventListener("scroll", throttledScrollHeaders);
8673
}
8774

8875
function unbindScroll() {
89-
window.removeEventListener("scroll", throttledScrollHeadersAndNavbar);
76+
window.removeEventListener("scroll", throttledScrollHeaders);
9077
}
9178

9279
function remToPx(rem) {
@@ -142,9 +129,6 @@ function setupShortcuts(shortcutDepth = 2) {
142129
// Done moving to clicked header; re-enable
143130
// scroll highlighting of shortcuts
144131
bindScroll();
145-
146-
// After scroll, display the navbar, if necessary
147-
scrollNavbar();
148132
});
149133
});
150134
});

assets/theme-css/fresh.css

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
.navbar.is-fresh {
2-
position: relative;
2+
position: sticky;
3+
top: 0px;
34
min-height: 3.8rem;
45
transition: all 0.3s;
56
z-index: 99;
@@ -70,18 +71,6 @@
7071
.navbar.is-fresh.is-fixed a:hover {
7172
color: #4fc1ea;
7273
}
73-
#navbar-clone {
74-
position: fixed;
75-
top: 0;
76-
left: 0;
77-
width: 100%;
78-
transform: translateY(-100%);
79-
z-index: 100;
80-
box-shadow: 0 0 8px rgba(0, 0, 0, 0.12);
81-
}
82-
#navbar-clone.is-active {
83-
transform: translateY(0);
84-
}
8574
.animated {
8675
animation-duration: 0.5s;
8776
animation-fill-mode: both;

layouts/_default/baseof.html

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
<body>
2525
{{ block "navbar" . }}
2626
{{ partial "navbar.html" . -}}
27-
{{ partial "navbar-clone.html" . -}}
2827
{{ end }}
2928

3029
{{ block "main" . }}

0 commit comments

Comments
 (0)