Skip to content

Instantly share code, notes, and snippets.

@davidanton1d
Last active August 29, 2015 14:16
Show Gist options
  • Save davidanton1d/0951e3062d210d313d3a to your computer and use it in GitHub Desktop.
Save davidanton1d/0951e3062d210d313d3a to your computer and use it in GitHub Desktop.
One-liner ugly jQuery sticky footer
// Sticky footer
$(document).ready(function adjustFooterMargin(){$("#footer").css("margin-top", Math.max(0, $(window).height() -$("#top").height() -$("#wrapper").height() -$("#footer").height() -50) + "px"); }); $(window).resize(function(){adjustFooterMargin(); });
// Simply adjust footer margin on load and resize.
// Ugly, but cheap for the client... :)
function adjustFooterMargin(){
$("#footer").css("margin-top", Math.max(0,
$(window).height()
// Main structure elements
-$("#top").height()
-$("#wrapper").height()
-$("#footer").height()
// Total padding on those structure elements
-50)
+ "px");
}
// Adjust on load
$(document).ready(function(){
adjustFooterMargin();
});
// Adjust on resize
$(window).resize(function(){
adjustFooterMargin();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment