Sticky Footers that move down when dynamic content gets loaded
- by Dominic Rodger
I've been using this snippet of jQuery to get a sticky footer:
if($(document.body).height() < $(window).height()){
$("#footer").css({position: "absolute",top:($(window).scrollTop()+$(window).height()-$("#footer").height())+"px", width: "100%"});
}
$(window).scroll(positionFooter).resize(positionFooter);
However, that breaks when I've got expandable/collapsible divs lying around where the original content was less high than the window, since it is then stuck to the bottom of the window, rather than the bottom of the document.
Is there a way of fixing this, or a better way of doing it?
Please bear in mind that I don't have much control over the HTML, since I need to do this in Django's admin interface, which doesn't allow much injection of HTML in the places you might want to to accomplish this sort of thing (i.e. this answer and this answer don't work for me).