Skip to content

Instantly share code, notes, and snippets.

@astromac
Last active May 18, 2016 03:59
Show Gist options
  • Save astromac/8325738 to your computer and use it in GitHub Desktop.
Save astromac/8325738 to your computer and use it in GitHub Desktop.
Positions content below a fixed header and does this everytime the window size changes
function contentOffset() {
var droppx = /\d+/;
var navheight = $('header > .navbar').css('height');
var subnavheight = $('header > .navbar + .sub-nav').css('height');
var breadcrumbheight = $('.breadcrumb').css('height');
var offset = 0;
if ($('.page-header').length > 0) {
var pageheaderheight = $('.page-header').css('height');
offset = parseInt(navheight.match(droppx)) + parseInt(subnavheight.match(droppx)) + parseInt(breadcrumbheight.match(droppx)) + parseInt(pageheaderheight.match(droppx)) + 1;
} else {
offset = parseInt(navheight.match(droppx)) + parseInt(subnavheight.match(droppx)) + parseInt(breadcrumbheight.match(droppx)) + 1;
}
$('header + .container').css('margin-top', offset);
}
// Position content below fixed header and do this everytime the window size changes
contentOffset();
$(window).resize(contentOffset);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment