Skip to content

Instantly share code, notes, and snippets.

@KinnaT
Created June 23, 2016 14:58
Show Gist options
  • Save KinnaT/7e55d3a79bb81a73d32d0122062f7a09 to your computer and use it in GitHub Desktop.
Save KinnaT/7e55d3a79bb81a73d32d0122062f7a09 to your computer and use it in GitHub Desktop.
jQuery header functions for making header sticky and moving the content down to match the responsive (variable) height
// Because the header changes height based on the variable height of the logo, position of the social box and height of the mobile menu
// Changes top margin of main content on resizing browser width
// Uncomment console.logs to check values against element heights
$j=jQuery.noConflict();
$j(window).on("load resize", function () {
if (window.innerWidth > 600) {
var headerHeight = jQuery(".header").height();
var navHeight = jQuery(".menu-container").outerHeight();
var combinedHeight = headerHeight + navHeight;
// console.log(combinedHeight);
jQuery("div.boxed").css("margin-top", combinedHeight);
}
else {
var headerHeight = jQuery(".topbar").height();
// console.log(headerHeight);
jQuery("div.boxed").css("margin-top", headerHeight);
}
});
// Sticky Header Class Added and Header Resize
$j(window).on("scroll touchmove", function () {
$j('.fixed-header').toggleClass('sticky-header', $j(document).scrollTop() > 30);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment