Skip to content

Instantly share code, notes, and snippets.

@parndt
Created July 25, 2010 04:58
Show Gist options
  • Save parndt/489315 to your computer and use it in GitHub Desktop.
Save parndt/489315 to your computer and use it in GitHub Desktop.
// makes the footer sit anchored on the bottom of the page
// change for whatever your DOM looks like.
$(document).ready(function(){
$(window).resize(adjust_footer);
$(document).add('img').load(adjust_footer);
});
adjust_footer = function() {
height = 0;
$('#page, #header').each(function(i, el) {
height += $(el).height();
$.each(['paddingTop', 'paddingBottom', 'marginTop', 'marginBottom'], function(j, attr) {
height += (parseInt($(el).css(attr), 0) || 0);
});
});
required_height = parseInt(window.innerHeight ? window.innerHeight : $(window.viewport).height());
$('#footer, #site_bar').each(function(i, el) {
required_height -= $(this).height();
required_height -= (parseInt($(this).css('marginTop'), 0) || 0);
required_height -= (parseInt($(this).css('marginBottom'), 0) || 0);
})
if (height < required_height) {
$('#page_container').css('height', required_height - 1);
} else {
$('#page_container').css('height', height);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment