Skip to content

Instantly share code, notes, and snippets.

@messa
Last active August 29, 2015 14:15
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 messa/a451564e28c981b779de to your computer and use it in GitHub Desktop.
Save messa/a451564e28c981b779de to your computer and use it in GitHub Desktop.
HTML footer always at the bottom
/// Keep footer always at the bottom, even when the page is too short
stickyFooter = function() {
jQuery(document).ready(function() {
var footer = jQuery("footer");
var body = jQuery(document.body);
var win = jQuery(window);
var fixed = false;
var positionFooter = function() {
var footerHeight = fixed ? footer.outerHeight() : 0;
if ((body.outerHeight() + footerHeight) < win.outerHeight()) {
footer.css({
"position": "absolute",
"bottom": 0
});
fixed = true;
} else {
footer.css({
"position": "static"
});
fixed = false;
}
};
win.scroll(positionFooter);
win.resize(positionFooter);
positionFooter();
});
};
stickyFooter();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment