Skip to content

Instantly share code, notes, and snippets.

@iammilton82
Last active December 17, 2015 11:19
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save iammilton82/5601454 to your computer and use it in GitHub Desktop.
Save iammilton82/5601454 to your computer and use it in GitHub Desktop.
Fixed scrolling navigation
/* CSS */
body { padding-top:80px; } /* be sure the padding is fron the top of the page to the top of your content */
#header { position: absolute; height:50px; width: 100%; top:20px; left:0; right:0; }
#header.fixed { position: fixed; top:0; }
(function () {
/****************** Sticky Navigation - This fixes an item at the bottom of the page ***************/
var banner = $("#footer");
var bottom = $(document).height() - 410;
$(window).scroll(function (event)
{
var y = $(this).scrollTop() + $(window).height();
if (y > bottom) {
$(banner).parent().removeClass('fixed');
} else {
$(banner).parent().addClass('fixed');
}
});
})(jQuery);
(function () {
/****************** Sticky Navigation ***************/
var banner = $("#header");
var top = 0;
$(window).scroll(function (event)
{
var y = $(this).scrollTop();
if (y > top) {
$(banner).addClass('fixed');
} else {
$(banner).removeClass('fixed');
}
});
})(jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment