Skip to content

Instantly share code, notes, and snippets.

@lisasy
Created November 13, 2014 02:22
Show Gist options
  • Save lisasy/92b914852851b842f2a4 to your computer and use it in GitHub Desktop.
Save lisasy/92b914852851b842f2a4 to your computer and use it in GitHub Desktop.
$(function() {
var $stickyEl = $("[data-waypoint='nav']");
var $stopEl = $("[data-waypoint='footer']");
var $verticalGutter = $stopEl.outerHeight()
$stickyEl.waypoint("sticky", function() {
$("[data-waypoint='main']").toggleClass("stuck");
});
$stopEl.waypoint(function (direction) {
if (direction == "down") {
var footerOffset = $stopEl.offset();
$stickyEl.css({
position: "absolute",
top: footerOffset.top - $stickyEl.outerHeight() - $verticalGutter
});
} else if (direction == "up") {
$stickyEl.attr("style", "");
}
}, {
offset: function () {
return $stickyEl.outerHeight();
}
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment