Created
November 11, 2013 07:25
-
-
Save mattgoucher/7409233 to your computer and use it in GitHub Desktop.
Anchor footer to bottom of page
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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