Skip to content

Instantly share code, notes, and snippets.

@drainpip
Last active December 11, 2015 06:39
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 drainpip/4560823 to your computer and use it in GitHub Desktop.
Save drainpip/4560823 to your computer and use it in GitHub Desktop.
Updates last section bottom padding inside a sticky footer design. This allows the top of the section to fit into the top of the viewport when the page would end at the top of the footer.
function updateHeight() {
if (($(window).height()) > $("section:last-child").height()) {
$("section:last-child").css("padding-bottom", $(window).height() - ($("section:last-child").height() + $("#footer").height() + 30) + "px"); // adjust the number for extra padding depending upon your site
} else {
$("section:last-child").css("padding-bottom", "0px");
}
}
// call on DOM load
updateHeight();
// call on window resize for portrait -> landscape
$(window).resize(function() {
updateHeight();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment