Skip to content

Instantly share code, notes, and snippets.

@awhedbee22
Last active August 29, 2015 14:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save awhedbee22/f586f57d97db9711856a to your computer and use it in GitHub Desktop.
Save awhedbee22/f586f57d97db9711856a to your computer and use it in GitHub Desktop.
// Fixed header
$(window).scroll(function(fixedHeader){
var headerHeight = $('#article-header').height();
var titleHeight = $('#article-header h1').outerHeight();
var fixedTop = (headerHeight - titleHeight);
if ($(this).scrollTop() >= fixedTop){
$('#article-header').addClass('fixedHeader');
$('#article-header.fixedHeader').css("top", -fixedTop);
}
if ($(this).scrollTop() < fixedTop){
$('#article-header').removeClass('fixedHeader');
$('#article-header').css('top', '0');
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment