Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions js/fixed-responsive-nav.js
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,38 @@
clearTapCheck();
}, false);
});

// Make header fixed when scrolling down for long lists
var pastTop = window.pageYOffset;
window.addEventListener("scroll", function() {

// Determine current positions and if the scroll was up
var top = window.pageYOffset,
header = document.querySelector("header"),
headerTop = header.style.top.slice(0,header.style.top.length-2),
scrollDown = top > pastTop;

// Check if navigation is open
if (document.querySelector(".opened")) {
// If scrolling down, make header absolute at current top position
if (scrollDown && header.style.position != "absolute") {
header.style.position = "absolute";
header.style.top = top + "px";
}
// Else if scrolling up above current top position, make header fixed
else if (header.style.position && top < headerTop) {
header.style = null;
}
}

// When navigation is closed, reset back to default
if (document.querySelector(".closed")) {
header.style = null;
}

// Sets new past top used to determine if scrolling down or up for next scroll
pastTop = top;
}, false);

}

Expand Down