Skip to content

Commit

Permalink
Issue 7: Fixes issue with long lists
Browse files Browse the repository at this point in the history
Fixes [adtile#7](adtile#7). It works with long lists now.
  • Loading branch information
MystK committed May 14, 2015
1 parent c6023c1 commit f6ce229
Showing 1 changed file with 32 additions and 0 deletions.
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

0 comments on commit f6ce229

Please sign in to comment.