From b6bf66accb493622400f22d16dae4d99afea6cd3 Mon Sep 17 00:00:00 2001 From: Verstalschik Date: Mon, 9 Feb 2015 13:23:08 +0300 Subject: [PATCH 1/3] fixed mac scroll bounce offset bug --- jquery.sticky-kit.js | 5 +++-- jquery.sticky-kit.min.js | 9 --------- 2 files changed, 3 insertions(+), 11 deletions(-) diff --git a/jquery.sticky-kit.js b/jquery.sticky-kit.js index 86029bd..4697346 100644 --- a/jquery.sticky-kit.js +++ b/jquery.sticky-kit.js @@ -33,7 +33,7 @@ enable_bottoming = true; } _fn = function(elm, padding_bottom, parent_top, parent_height, top, height, el_float, detached) { - var bottomed, detach, fixed, last_pos, offset, parent, recalc, recalc_and_tick, recalc_counter, spacer, tick; + var bottomed, detach, fixed, last_pos, offset, parent, recalc, recalc_and_tick, recalc_counter, spacer, tick, scroll_height; 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..e69de29 100644 --- a/jquery.sticky-kit.min.js +++ b/jquery.sticky-kit.min.js @@ -1,9 +0,0 @@ -/* - 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"))),lb&&!u&&(c-=k,c=Math.max(b-t,c),c=Math.min(p,c),m&&a.css({top:c+"px"})))):l>D&&(m=!0,b={position:"fixed",top:c},b.width="border-box"===a.css("box-sizing")?a.outerWidth()+"px":a.width()+"px",a.css(b).addClass(s),null==n&&(a.after(g),"left"!==r&&"right"!==r||g.append(a)),a.trigger("sticky_kit:stick")),m&&v&&(null==h&&(h=l+t+c>z+q),!u&&h)))return u=!0,"static"===f.css("position")&&f.css({position:"relative"}),a.css({position:"absolute",bottom:d,top:"auto"}).trigger("sticky_kit:bottom")}, -w=function(){B();return b()},F=function(){E=!0;e.off("touchmove",b);e.off("scroll",b);e.off("resize",w);k(document.body).off("sticky_kit:recalc",w);a.off("sticky_kit:detach",F);a.removeData("sticky_kit");a.css({position:"",bottom:"",top:"",width:""});f.position("position","");if(m)return null==n&&("left"!==r&&"right"!==r||a.insertAfter(g),g.remove()),a.removeClass(s)},e.on("touchmove",b),e.on("scroll",b),e.on("resize",w),k(document.body).on("sticky_kit:recalc",w),a.on("sticky_kit:detach",F),setTimeout(b, -0)}};q=0;for(H=this.length;q Date: Mon, 9 Feb 2015 22:27:07 +0300 Subject: [PATCH 2/3] fixed in coffee file too --- jquery.sticky-kit.coffee | 5 +++-- jquery.sticky-kit.js | 6 +++--- 2 files changed, 6 insertions(+), 5 deletions(-) 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 4697346..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,8 +32,8 @@ if (enable_bottoming == null) { enable_bottoming = true; } - _fn = function(elm, padding_bottom, parent_top, parent_height, top, height, el_float, detached) { - var bottomed, detach, fixed, last_pos, offset, parent, recalc, recalc_and_tick, recalc_counter, spacer, tick, scroll_height; + _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; } From 5793101ba1c5f6fc8c0037c9d9727d187881ec25 Mon Sep 17 00:00:00 2001 From: egych Date: Mon, 9 Feb 2015 22:32:32 +0300 Subject: [PATCH 3/3] added minified version --- jquery.sticky-kit.min.js | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/jquery.sticky-kit.min.js b/jquery.sticky-kit.min.js index e69de29..5bbd9ab 100644 --- a/jquery.sticky-kit.min.js +++ b/jquery.sticky-kit.min.js @@ -0,0 +1,9 @@ +/* + Sticky-kit v1.1.1 | WTFPL | Leaf Corcoran 2014 | http://leafo.net +*/ +(function(){var b,l;b=this.jQuery||window.jQuery;l=b(window);b.fn.stick_in_parent=function(d){var n,A,p,q,g,E,u,x,r,I;null==d&&(d={});u=d.sticky_class;A=d.inner_scrolling;E=d.recalc_every;g=d.parent;q=d.offset_top;p=d.spacer;n=d.bottoming;null==q&&(q=0);null==g&&(g=void 0);null==A&&(A=!0);null==u&&(u="is_stuck");null==n&&(n=!0);x=function(a,d,r,B,F,v,t,G,x){var w,H,m,C,c,e,D,y,z,f,h;if(!a.data("sticky_kit")){a.data("sticky_kit",!0);e=a.parent();null!=g&&(e=e.closest(g));if(!e.length)throw"failed to find stick parent"; +w=m=!1;(f=null!=p?p&&a.closest(p):b("
"))&&f.css("position",a.css("position"));D=function(){var c,n,k;if(!G&&(c=parseInt(e.css("border-top-width"),10),n=parseInt(e.css("padding-top"),10),d=parseInt(e.css("padding-bottom"),10),r=e.offset().top+c+n,B=e.height(),x=b(document).height()-l.height(),m&&(w=m=!1,null==p&&(a.insertAfter(f),f.detach()),a.css({position:"",top:"",width:"",bottom:""}).removeClass(u),k=!0),F=a.offset().top-(parseInt(a.css("margin-top"),10)||0)-q,v=a.outerHeight(!0),t=a.css("float"), +f&&f.css({width:a.outerWidth(!0),height:v,display:a.css("display"),"vertical-align":a.css("vertical-align"),"float":t}),k))return h()};D();if(v!==B)return C=void 0,c=q,z=E,h=function(){var b,h,k,g;if(!G&&(null!=z&&(--z,0>=z&&(z=E,D())),k=l.scrollTop(),null!=C&&(h=x>k?k-C:0),C=k,m?(n&&(g=k+v+c>B+r,w&&!g&&(w=!1,a.css({position:"fixed",bottom:"",top:c}).trigger("sticky_kit:unbottom"))),kb&&!w&&(c-=h,c=Math.max(b-v,c),c=Math.min(q,c),m&&a.css({top:c+"px"})))):k>F&&(m=!0,b={position:"fixed",top:c},b.width="border-box"===a.css("box-sizing")?a.outerWidth()+"px":a.width()+"px",a.css(b).addClass(u),null==p&&(a.after(f),"left"!==t&&"right"!==t||f.append(a)),a.trigger("sticky_kit:stick")),m&&n&&(null==g&&(g=k+v+c>B+r),!w&&g)))return w=!0,"static"===e.css("position")&&e.css({position:"relative"}),a.css({position:"absolute",bottom:d,top:"auto"}).trigger("sticky_kit:bottom")}, +y=function(){D();return h()},H=function(){G=!0;l.off("touchmove",h);l.off("scroll",h);l.off("resize",y);b(document.body).off("sticky_kit:recalc",y);a.off("sticky_kit:detach",H);a.removeData("sticky_kit");a.css({position:"",bottom:"",top:"",width:""});e.position("position","");if(m)return null==p&&("left"!==t&&"right"!==t||a.insertAfter(f),f.remove()),a.removeClass(u)},l.on("touchmove",h),l.on("scroll",h),l.on("resize",y),b(document.body).on("sticky_kit:recalc",y),a.on("sticky_kit:detach",H),setTimeout(h, +0)}};r=0;for(I=this.length;r