Skip to content

Instantly share code, notes, and snippets.

@mattgoucher
Created November 11, 2013 07:25
Show Gist options
  • Save mattgoucher/7409233 to your computer and use it in GitHub Desktop.
Save mattgoucher/7409233 to your computer and use it in GitHub Desktop.
Anchor footer to bottom of page
(function() {
var win, page, footer;
// Push the footer to the bottom of the page.
function anchorFooter() {
var winHeight = win.outerHeight(),
pageBottom = page.outerHeight(true) + page.position().top,
gap = (winHeight - pageBottom) - footer.outerHeight(true);
if (winHeight > pageBottom && gap > 1) {
footer.css("top", gap);
}else if (gap < 1) {
footer.css("top", "auto");
}
}
$(function() {
// Cache DOM Elements
win = $(window),
page = $("#page"),
footer = $("#footer");
// Anchor the footer on load/resize, trigger a resize to start.
win.on("load resize", anchorFooter).resize();
});
}());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment