Skip to content

Instantly share code, notes, and snippets.

@whatnickcodes
Created September 16, 2014 16:45
Show Gist options
  • Save whatnickcodes/7edb6bc06982b438712b to your computer and use it in GitHub Desktop.
Save whatnickcodes/7edb6bc06982b438712b to your computer and use it in GitHub Desktop.
$(function() {
fixedHeader();
});
$(window).scroll(function() {
fixedHeader();
});
$(window).resize(function() {
fixedHeader();
});
function fixedHeader() {
var yScroll = $(window).scrollTop();
var distance = 80- yScroll;
// distance = distance + 80;
if (distance <= 0) {
$('body').addClass('sticky');
} else {
$('body').removeClass('sticky');
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment