Posted By

jayphen on 03/07/10


Tagged

footer position


Versions (?)

Who likes this?

5 people have marked this snippet as a favorite

jannisg
cdnicoll
wattsupnow
johnw
wirenaught


jQuery Sticky Footer


 / Published in: jQuery
 

  1. //footer stick
  2. $(window).bind("load", function() {
  3.  
  4. var footerHeight = 0,
  5. footerTop = 0,
  6. $footer = $("#footer");
  7.  
  8. positionFooter();
  9.  
  10. function positionFooter() {
  11. footerHeight = $footer.outerHeight();
  12. footerTop = ($(window).scrollTop()+$(window).height()-footerHeight)+"px";
  13. if ( ($(document.body).height()+footerHeight) < $(window).height()) {
  14. $footer.css({
  15. position: "absolute",
  16. top: footerTop
  17. });
  18. } else {
  19. $footer.css({
  20. position: "static"
  21. });
  22. }
  23. };
  24. $(window)
  25. .scroll(positionFooter)
  26. .resize(positionFooter);
  27.  
  28. });

Report this snippet  

You need to login to post a comment.