Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue 7: Fixes issue with long lists #16

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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