Skip to content

Commit a30f76f

Browse files
committed
Fix nav spacing, update resume.
1 parent 2dd5ae7 commit a30f76f

File tree

3 files changed

+65
-67
lines changed

3 files changed

+65
-67
lines changed

_includes/navbar.html

+1-2
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@
99
title="linkedin"></a></div>
1010
<div><a href="/resume" class="fa fa-address-card-o" aria-hidden="true" title="resume"></a></div>
1111
<div><a href="/feed.xml" class="fa fa-rss" aria-hidden="true" title="rss"></a></div>
12-
<div id="hamburger" class="hamburger"><a class="fa fa-bars" aria-hidden="true" title="links"
13-
onclick="test(event)"></a></div>
12+
<div id="hamburger" class="hamburger"><a class="fa fa-bars" aria-hidden="true" title="links"></a></div>
1413
</div>
1514
<div id="navbar-drawer" class="navbar-drawer">
1615
<a href="/">

_sass/blog.scss

-3
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ $breakpoint-mobile: 768px;
1111

1212
@media(max-width: $breakpoint-mobile) {
1313
div.blog-list-container {
14-
margin-top: 114px !important;
1514
padding: 0 !important;
1615
}
1716
}
@@ -28,8 +27,6 @@ $breakpoint-mobile: 768px;
2827

2928
@media(max-width: $breakpoint-navbar) {
3029
.blog-list-container {
31-
margin-top: 146px !important;
32-
3330
.blog-list {
3431
padding-top: 2rem;
3532
}

assets/js/navbar.js

+64-62
Original file line numberDiff line numberDiff line change
@@ -1,88 +1,90 @@
11
class Navbar {
2-
32
constructor() {
4-
this.navbarHamburger = document.getElementById("hamburger")
5-
this.navbarDrawer = document.getElementById("navbar-drawer")
6-
this.navbarHeader = document.getElementById("navbar-header")
7-
this.pageContainer = document.getElementsByClassName("page-container")[0]
8-
this.navbar = document.getElementById("navbar")
9-
this.y = window.scrollY;
10-
this.velocityY = 0;
11-
this.accelerationY = 0;
12-
this.jerkY = 0;
3+
this.navbar = document.getElementById("navbar");
4+
this.navbarHamburger = document.getElementById("hamburger");
5+
this.navbarDrawer = document.getElementById("navbar-drawer");
6+
this.navbarHeader = document.getElementById("navbar-header");
7+
this.pageContainer = document.querySelector(".page-container");
138

14-
window.addEventListener("scroll", () => {
15-
this.onScroll()
16-
})
9+
this.lastScrollY = window.scrollY;
10+
this.lastInnerHeight = window.innerHeight;
11+
this.navbarVisible = true;
12+
this.isOpened = false;
13+
this.isScrolling = false;
1714

18-
document.addEventListener("click", (e) => {
15+
window.addEventListener("scroll", () => this.onScroll());
16+
document.addEventListener("click", (e) => this.onClick(e));
1917

20-
if (this.navbarHeader.contains(e.target)) {
18+
this.observeViewportResize();
19+
}
2120

22-
if (this.isOpened) {
23-
this.closeDrawer()
24-
}
25-
else {
26-
this.openDrawer()
27-
}
21+
observeViewportResize() {
22+
window.addEventListener("resize", () => {
23+
if (window.innerHeight > this.lastInnerHeight) {
24+
this.showNavbar();
2825
}
26+
this.lastInnerHeight = window.innerHeight;
27+
});
28+
}
29+
30+
onScroll() {
31+
if (this.isScrolling) return;
2932

30-
else if (!this.navbarDrawer.contains(e.target)) {
31-
if (this.isOpened) {
32-
this.closeDrawer()
33-
}
33+
this.isScrolling = true;
34+
requestAnimationFrame(() => {
35+
const currentY = window.scrollY;
36+
const velocityY = currentY - this.lastScrollY;
37+
38+
if (velocityY < -20 || currentY === 0) {
39+
this.showNavbar();
40+
} else if (!this.isOpened && velocityY > 0) {
41+
this.hideNavbar();
3442
}
35-
})
36-
}
3743

38-
showNavbar() {
39-
this.navbar.classList.remove("hide")
40-
this.navbarShown = !!!this.navbarShown
44+
this.lastScrollY = currentY;
45+
this.isScrolling = false;
46+
});
4147
}
4248

43-
hideNavbar() {
44-
this.navbar.classList.add("hide")
45-
this.navbarShown = !!!this.navbarShown
49+
onClick(e) {
50+
if (this.navbarHeader.contains(e.target)) {
51+
this.isOpened ? this.closeDrawer() : this.openDrawer();
52+
} else if (!this.navbarDrawer.contains(e.target) && this.isOpened) {
53+
this.closeDrawer();
54+
}
4655
}
4756

48-
onScroll(threshold = 30) {
49-
const y = window.scrollY
50-
const velocityY = y - this.y
51-
const accelerationY = velocityY - this.velocityY
52-
const jerkY = accelerationY - this.accelerationY
53-
54-
55-
if (((-jerkY) > threshold && velocityY < 0) || y === 0) {
56-
this.showNavbar()
57+
showNavbar() {
58+
if (!this.navbarVisible) {
59+
this.navbar.classList.remove("hide");
60+
this.navbarVisible = true;
5761
}
58-
else if (!this.isOpened && document.body.scrollHeight > document.body.clientHeight && velocityY > 0 && y > 0) {
59-
this.hideNavbar()
62+
}
63+
64+
hideNavbar() {
65+
if (this.navbarVisible) {
66+
this.navbar.classList.add("hide");
67+
this.navbarVisible = false;
6068
}
61-
this.y = y
62-
this.velocityY = velocityY
63-
this.accelerationY = accelerationY
64-
this.jerkY = jerkY
6569
}
6670

6771
openDrawer() {
68-
this.pageContainer.classList.add("navbar-open")
69-
this.navbar.classList.add("open")
70-
this.navbarDrawer.classList.add("open")
71-
this.navbarHeader.classList.add("opened")
72-
this.isOpened = !!!this.isOpened
72+
this.pageContainer.classList.add("navbar-open");
73+
this.navbar.classList.add("open");
74+
this.navbarDrawer.classList.add("open");
75+
this.navbarHeader.classList.add("opened");
76+
this.isOpened = true;
7377
}
7478

7579
closeDrawer() {
76-
this.pageContainer.classList.remove("navbar-open")
77-
this.navbar.classList.remove("open")
78-
this.navbarDrawer.classList.remove("open")
79-
this.navbarHeader.classList.remove("opened")
80-
this.isOpened = !!!this.isOpened
80+
this.pageContainer.classList.remove("navbar-open");
81+
this.navbar.classList.remove("open");
82+
this.navbarDrawer.classList.remove("open");
83+
this.navbarHeader.classList.remove("opened");
84+
this.isOpened = false;
8185
}
8286
}
8387

84-
let navbar;
85-
8688
window.addEventListener("load", () => {
87-
navbar = new Navbar()
88-
})
89+
new Navbar();
90+
});

0 commit comments

Comments
 (0)