/ Published in: jQuery
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
/** * 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);