Posted By

javifr on 10/29/10


Tagged

jquery footer sticky


Versions (?)

Who likes this?

5 people have marked this snippet as a favorite

stegwee
Tyster
verostudios
wirenaught
Beppoi


jQuery Sticky Footer


 / Published in: JavaScript
 

  1. // Window load event used just in case window height is dependant upon images
  2. $(window).bind("load", function() {
  3.  
  4. var footerHeight = 0,
  5. footerTop = 0,
  6. $footer = $("#footer");
  7.  
  8. positionFooter();
  9.  
  10. function positionFooter() {
  11.  
  12. footerHeight = $footer.height();
  13. footerTop = ($(window).scrollTop()+$(window).height()-footerHeight)+"px";
  14.  
  15. if ( ($(document.body).height()+footerHeight) < $(window).height()) {
  16. $footer.css({
  17. position: "absolute"
  18. }).animate({
  19. top: footerTop
  20. })
  21. } else {
  22. $footer.css({
  23. position: "static"
  24. })
  25. }
  26.  
  27. }
  28.  
  29. $(window)
  30. .scroll(positionFooter)
  31. .resize(positionFooter)
  32.  
  33. });

Report this snippet  

You need to login to post a comment.