This is an update to the previous entry, 'Making sure your footer always sticks to the bottom of the page' - refer to that post for greater detail and explanations of what exactly goes on here.
So, as I mentioned previously, this function comes in really handy when you want to stick a footer to the bottom of a short page; i.e. to ensure that something that's meant to be at the bottom of the viewport actually sticks there rather than floating in the middle of the ether if you've got a short page of content.
However, when working on a new project last night, I noticed this faithful piece of code wasn't working properly in IE. At the same time, I was getting frustrated at some ridiculously slow page load speeds - this is a site on my local machine, so there shouldn't be any delay! I finally narrowed it down to, of all things, the Google Fonts API running incredibly slowly and even failing to load some files at all. This loading delay caused jQuery to miscalculate the length of the viewport, and so subsequently not stick my footer in the right place. Which was frustrating.
The solution came in the form of bind("load"), which I have since learned fires after practically all major elements of a page have been loaded, including the page, CSS, images, and, crucially, font-faces.
So the new, updated, fresh-faced and doe-eyed function now looks like this:
   <!--Â
  Â
   $(window).bind("load", function() {
    var docHeight = $(window).height();
    var footerHeight = $('#footer').height();
    var footerTop = $('#footer').position().top + footerHeight;
   Â
    if (footerTop < docHeight) {
     $('#footer').css('margin-top', 10 + (docHeight - footerTop) + 'px');
    }
   });
  Â
   // -->
  </script>
It's worth noting that, for this particular project I am using two different Google Web Fonts for both the h1-h5 tags and the regular body text, which is something I haven't done before. Also worth noting that this issue doesn't present in Firefox, so if you couldn't give a shit about IE (and I know a lot of you don't), then please go back in time and ignore this post.
-
Gwen
-
http://twitter.com/scottgumbleton Scott Gumbleton
-
http://blog.gaijindesign.com/ Lawrie Malen
-


