Skip to content

Instantly share code, notes, and snippets.

@corypina
Last active July 17, 2020 23:11
Show Gist options
  • Save corypina/ce124115238f0f3a78943cbb0ed7a5ad to your computer and use it in GitHub Desktop.
Save corypina/ce124115238f0f3a78943cbb0ed7a5ad to your computer and use it in GitHub Desktop.
Min-height for main content area
// Calculate
(function ($) {
// Bind to the resize event of the window object
$(window)
.on("resize", function () {
let wpadmin;
if ($("#wpadminbar")) { // in case WP admin bar is present
wpadmin = $("#wpadminbar").height();
} else {
wpadmin = 0;
}
let footer = $("footer").height();
let header = $("header").height();
let screen = $(window).height();
// Set min-width of main element to:
// screen height - (footer, header, and maybe admin bar)
$(".content").css(
"min-height",
screen - (footer + header + wpadmin)
);
// Invoke the resize event immediately
})
.resize(); // run resize immediately
})(jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment