diff --git a/jquery.sticky-kit.coffee b/jquery.sticky-kit.coffee index fb6f287..121b69d 100644 --- a/jquery.sticky-kit.coffee +++ b/jquery.sticky-kit.coffee @@ -24,7 +24,7 @@ $.fn.stick_in_parent = (opts={}) -> enable_bottoming = true unless enable_bottoming? for elm in @ - ((elm, padding_bottom, parent_top, parent_height, top, height, el_float, detached) -> + ((elm, padding_bottom, parent_top, parent_height, top, height, el_float, detached, scroll_height) -> return if elm.data "sticky_kit" elm.data "sticky_kit", true @@ -49,6 +49,7 @@ $.fn.stick_in_parent = (opts={}) -> parent_top = parent.offset().top + border_top + padding_top parent_height = parent.height() + scroll_height = $(document).height() - win.height() if fixed fixed = false @@ -101,7 +102,7 @@ $.fn.stick_in_parent = (opts={}) -> scroll = win.scrollTop() if last_pos? - delta = scroll - last_pos + delta = if scroll_height > scroll then scroll - last_pos else 0 last_pos = scroll if fixed diff --git a/jquery.sticky-kit.js b/jquery.sticky-kit.js index 86029bd..dceda0a 100644 --- a/jquery.sticky-kit.js +++ b/jquery.sticky-kit.js @@ -1,4 +1,4 @@ -// Generated by CoffeeScript 1.8.0 +// Generated by CoffeeScript 1.9.0 /** @license Sticky-kit v1.1.1 | WTFPL | Leaf Corcoran 2014 | http://leafo.net @@ -32,7 +32,7 @@ if (enable_bottoming == null) { enable_bottoming = true; } - _fn = function(elm, padding_bottom, parent_top, parent_height, top, height, el_float, detached) { + _fn = function(elm, padding_bottom, parent_top, parent_height, top, height, el_float, detached, scroll_height) { var bottomed, detach, fixed, last_pos, offset, parent, recalc, recalc_and_tick, recalc_counter, spacer, tick; if (elm.data("sticky_kit")) { return; @@ -61,6 +61,7 @@ padding_bottom = parseInt(parent.css("padding-bottom"), 10); parent_top = parent.offset().top + border_top + padding_top; parent_height = parent.height(); + scroll_height = $(document).height() - win.height(); if (fixed) { fixed = false; bottomed = false; @@ -113,7 +114,7 @@ } scroll = win.scrollTop(); if (last_pos != null) { - delta = scroll - last_pos; + delta = scroll_height > scroll ? scroll - last_pos : 0; } last_pos = scroll; if (fixed) { diff --git a/jquery.sticky-kit.min.js b/jquery.sticky-kit.min.js index 87f7d57..5bbd9ab 100644 --- a/jquery.sticky-kit.min.js +++ b/jquery.sticky-kit.min.js @@ -1,9 +1,9 @@ /* Sticky-kit v1.1.1 | WTFPL | Leaf Corcoran 2014 | http://leafo.net */ -(function(){var k,e;k=this.jQuery||window.jQuery;e=k(window);k.fn.stick_in_parent=function(d){var v,y,n,p,h,C,s,G,q,H;null==d&&(d={});s=d.sticky_class;y=d.inner_scrolling;C=d.recalc_every;h=d.parent;p=d.offset_top;n=d.spacer;v=d.bottoming;null==p&&(p=0);null==h&&(h=void 0);null==y&&(y=!0);null==s&&(s="is_stuck");null==v&&(v=!0);G=function(a,d,q,z,D,t,r,E){var u,F,m,A,c,f,B,w,x,g,b;if(!a.data("sticky_kit")){a.data("sticky_kit",!0);f=a.parent();null!=h&&(f=f.closest(h));if(!f.length)throw"failed to find stick parent"; -u=m=!1;(g=null!=n?n&&a.closest(n):k("
"))&&g.css("position",a.css("position"));B=function(){var c,e,l;if(!E&&(c=parseInt(f.css("border-top-width"),10),e=parseInt(f.css("padding-top"),10),d=parseInt(f.css("padding-bottom"),10),q=f.offset().top+c+e,z=f.height(),m&&(u=m=!1,null==n&&(a.insertAfter(g),g.detach()),a.css({position:"",top:"",width:"",bottom:""}).removeClass(s),l=!0),D=a.offset().top-(parseInt(a.css("margin-top"),10)||0)-p,t=a.outerHeight(!0),r=a.css("float"),g&&g.css({width:a.outerWidth(!0), -height:t,display:a.css("display"),"vertical-align":a.css("vertical-align"),"float":r}),l))return b()};B();if(t!==z)return A=void 0,c=p,x=C,b=function(){var b,k,l,h;if(!E&&(null!=x&&(--x,0>=x&&(x=C,B())),l=e.scrollTop(),null!=A&&(k=l-A),A=l,m?(v&&(h=l+t+c>z+q,u&&!h&&(u=!1,a.css({position:"fixed",bottom:"",top:c}).trigger("sticky_kit:unbottom"))),l