Return to Snippet

Revision: 19864
at November 2, 2009 12:02 by joshuabaker


Initial Code
/**
 * jQuery.stickyFooter - Sticky footer plugin
 * @author Joshua Baker
 * @version 1.0.0
 */
;(function($){
  
  // Defined jQuery.stickyFooterPos();
  // Outputs a console message until $(element).stickyFooter(); is run
  $.extend({
    stickyFooterPos: function() { console.log('jQuery.stickyFooterPos() has not been initialized.'); }
  });
  
  // Define jQuery(element).stickyFooter();
  $.fn.extend({
    stickyFooter: function() {
      // Create the footer push element
      var stickyFooterPush = $('<div style="clear:both;"></div>');
      
      // Append a clear to the bottom of the body to handle any potential float issues
      $('body').append('<div style="clear:both;"></div>');
      
      // Place the footer push above the selected footer element
      $(this).before(stickyFooterPush);
      
      // Re-define jQuery.stickyFooterPos();
      // This can be called at any point after
      $.extend({
        stickyFooterPos: function() {
          var documentHeight = $(document.body).height() - stickyFooterPush.height();
          var windowHeight = $(window).height();
          if (documentHeight < windowHeight) {
            stickyFooterPush.height(windowHeight - documentHeight);
          }
        }
      });
      
      // Initial run (on DOM ready)
      $.stickyFooterPos();
      
      // Bind events to loading, resizing and scrolling of the window
      $(window).bind('load resize scroll', $.stickyFooterPos);
    }
  });
  
})(jQuery);



/**
 * jQuery.stickyFooter - Sticky footer plugin
 * @author Joshua Baker
 * @version 1.0.0
 */
;(function(a){a.extend({stickyFooterPos:function(){console.log("jQuery.stickyFooterPos() has not been initialized.")}});a.fn.extend({stickyFooter:function(){var b=a('<div style="clear:both;"></div>');a("body").append('<div style="clear:both;"></div>');a(this).before(b);a.extend({stickyFooterPos:function(){var c=a(document.body).height()-b.height();var d=a(window).height();if(c<d){b.height(d-c)}}});a.stickyFooterPos();a(window).bind("load resize scroll",a.stickyFooterPos)}})})(jQuery);

Initial URL


Initial Description


Initial Title
jQuery.stickyFooter

Initial Tags
jquery

Initial Language
jQuery