- commit
- 3ecd7041729bbdb55855d12745233a1adb50a6c5
- parent
- 51c6a4038a84c905132a5d0138e8bb45410c2275
- Author
- leaf corcoran <leafot@gmail.com>
- Date
- 2013-09-11 07:17
fix recalc for when elements are currently stuck #5
Diffstat
| M | jquery.sticky-kit.coffee | 10 | ++++++++-- |
| M | jquery.sticky-kit.js | 8 | +++++--- |
| M | jquery.sticky-kit.min.js | 8 | ++++---- |
| M | site/www/src/jquery.sticky-kit.js | 8 | +++++--- |
| M | site/www/src/jquery.sticky-kit.min.js | 8 | ++++---- |
5 files changed, 26 insertions, 16 deletions
diff --git a/jquery.sticky-kit.coffee b/jquery.sticky-kit.coffee
@@ -25,8 +25,13 @@ $.fn.stick_in_parent = (opts={}) ->
25 25 parent_top = parent.offset().top + border_top + padding_top
26 26 parent_height = parent.height()
27 27
28 -1 top = elm.offset().top - parseInt elm.css("margin-top"), 10
29 -1 height = elm.outerHeight true
-1 28 sizing_elm = if elm.is ".is_stuck"
-1 29 spacer
-1 30 else
-1 31 elm
-1 32
-1 33 top = sizing_elm.offset().top - parseInt sizing_elm.css("margin-top"), 10
-1 34 height = sizing_elm.outerHeight true
30 35
31 36 recalc()
32 37 return if height == parent_height
@@ -38,6 +43,7 @@ $.fn.stick_in_parent = (opts={}) ->
38 43 width: elm.outerWidth true
39 44 height: height
40 45 display: elm.css "display"
-1 46 "vertical-align": elm.css "vertical-align"
41 47 float: float
42 48 })
43 49
diff --git a/jquery.sticky-kit.js b/jquery.sticky-kit.js
@@ -37,14 +37,15 @@ 37 37 throw "failed to find stick parent"; 38 38 } 39 39 recalc = function() {40 -1 var border_top, padding_top;-1 40 var border_top, padding_top, sizing_elm; 41 41 border_top = parseInt(parent.css("border-top-width"), 10); 42 42 padding_top = parseInt(parent.css("padding-top"), 10); 43 43 padding_bottom = parseInt(parent.css("padding-bottom"), 10); 44 44 parent_top = parent.offset().top + border_top + padding_top; 45 45 parent_height = parent.height();46 -1 top = elm.offset().top - parseInt(elm.css("margin-top"), 10);47 -1 return height = elm.outerHeight(true);-1 46 sizing_elm = elm.is(".is_stuck") ? spacer : elm; -1 47 top = sizing_elm.offset().top - parseInt(sizing_elm.css("margin-top"), 10); -1 48 return height = sizing_elm.outerHeight(true); 48 49 }; 49 50 recalc(); 50 51 if (height === parent_height) { @@ -55,6 +56,7 @@ 55 56 width: elm.outerWidth(true), 56 57 height: height, 57 58 display: elm.css("display"), -1 59 "vertical-align": elm.css("vertical-align"), 58 60 float: float 59 61 }); 60 62 fixed = false;
diff --git a/jquery.sticky-kit.min.js b/jquery.sticky-kit.min.js
@@ -1,7 +1,7 @@ 1 1 /* 2 2 Sticky-kit v0.0.1 | WTFPL | Leaf Corcoran 2013 | http://leafo.net 3 3 */4 -1 (function(){var g,s;g=this.jQuery;s=g(window);g.fn.stick_in_parent=function(e){var t,c,p,A,k,B;null==e&&(e={});p=e.sticky_class;t=e.inner_scrolling;c=e.parent;null==c&&(c=void 0);null==t&&(t=!0);null==p&&(p="is_stuck");A=function(a,e,k,u,x,l){var n,q,f,v,b,d,y,z,r,w;d=a.parent();null!=c&&(d=d.closest(c));if(!d.length)throw"failed to find stick parent";y=function(){var b,f;b=parseInt(d.css("border-top-width"),10);f=parseInt(d.css("padding-top"),10);e=parseInt(d.css("padding-bottom"),10);k=d.offset().top+5 -1 b+f;u=d.height();x=a.offset().top-parseInt(a.css("margin-top"),10);return l=a.outerHeight(!0)};y();if(l!==u)return f=a.css("float"),r=g("<div />").css({width:a.outerWidth(!0),height:l,display:a.css("display"),"float":f}),n=q=!1,v=void 0,b=0,z=!1,w=function(){var h,g,m,c;m=s.scrollTop();null!=v&&(g=m-v);v=m;q?(c=m+l+b>u+k,n&&!c&&(n=!1,a.css({position:"fixed",bottom:"",top:0}).trigger("sticky_kit:unbottom")),m<x&&(q=!1,b=0,"left"!==f&&"right"!==f||a.insertAfter(r),r.detach(),h={position:""},z&&(h.width=6 -1 ""),a.css(h).removeClass(p).trigger("sticky_kit:unstick")),t&&(h=s.height(),l>h&&!n&&(b-=g,b=Math.max(h-l,b),b=Math.min(0,b),a.css({top:b+"px"})))):m>x&&(q=!0,h={position:"fixed",top:b},"none"===f&&"block"===a.css("display")&&(h.width=a.width()+"px",z=!0),a.css(h).addClass(p).after(r),"left"!==f&&"right"!==f||r.append(a),a.trigger("sticky_kit:stick"));if(q&&(null==c&&(c=m+l+b>u+k),!n&&c))return n=!0,"static"===d.css("position")&&d.css({position:"relative"}),a.css({position:"absolute",bottom:e,top:""}).trigger("sticky_kit:bottom")},7 -1 s.on("scroll",w),setTimeout(w,0),g(document.body).on("sticky_kit:recalc",function(){y();return w()})};k=0;for(B=this.length;k<B;k++)e=this[k],A(g(e));return this}}).call(this);-1 4 (function(){var g,s;g=this.jQuery;s=g(window);g.fn.stick_in_parent=function(f){var t,d,q,A,h,B;null==f&&(f={});q=f.sticky_class;t=f.inner_scrolling;d=f.parent;null==d&&(d=void 0);null==t&&(t=!0);null==q&&(q="is_stuck");A=function(a,f,h,u,x,k){var n,r,l,v,c,e,y,z,p,w;e=a.parent();null!=d&&(e=e.closest(d));if(!e.length)throw"failed to find stick parent";y=function(){var b,c;b=parseInt(e.css("border-top-width"),10);c=parseInt(e.css("padding-top"),10);f=parseInt(e.css("padding-bottom"),10);h=e.offset().top+ -1 5 b+c;u=e.height();b=a.is(".is_stuck")?p:a;x=b.offset().top-parseInt(b.css("margin-top"),10);return k=b.outerHeight(!0)};y();if(k!==u)return l=a.css("float"),p=g("<div />").css({width:a.outerWidth(!0),height:k,display:a.css("display"),"vertical-align":a.css("vertical-align"),float:l}),n=r=!1,v=void 0,c=0,z=!1,w=function(){var b,g,m,d;m=s.scrollTop();null!=v&&(g=m-v);v=m;r?(d=m+k+c>u+h,n&&!d&&(n=!1,a.css({position:"fixed",bottom:"",top:0}).trigger("sticky_kit:unbottom")),m<x&&(r=!1,c=0,"left"!==l&&"right"!== -1 6 l||a.insertAfter(p),p.detach(),b={position:""},z&&(b.width=""),a.css(b).removeClass(q).trigger("sticky_kit:unstick")),t&&(b=s.height(),k>b&&!n&&(c-=g,c=Math.max(b-k,c),c=Math.min(0,c),a.css({top:c+"px"})))):m>x&&(r=!0,b={position:"fixed",top:c},"none"===l&&"block"===a.css("display")&&(b.width=a.width()+"px",z=!0),a.css(b).addClass(q).after(p),"left"!==l&&"right"!==l||p.append(a),a.trigger("sticky_kit:stick"));if(r&&(null==d&&(d=m+k+c>u+h),!n&&d))return n=!0,"static"===e.css("position")&&e.css({position:"relative"}), -1 7 a.css({position:"absolute",bottom:f,top:""}).trigger("sticky_kit:bottom")},s.on("scroll",w),setTimeout(w,0),g(document.body).on("sticky_kit:recalc",function(){y();return w()})};h=0;for(B=this.length;h<B;h++)f=this[h],A(g(f));return this}}).call(this);
diff --git a/site/www/src/jquery.sticky-kit.js b/site/www/src/jquery.sticky-kit.js
@@ -37,14 +37,15 @@ 37 37 throw "failed to find stick parent"; 38 38 } 39 39 recalc = function() {40 -1 var border_top, padding_top;-1 40 var border_top, padding_top, sizing_elm; 41 41 border_top = parseInt(parent.css("border-top-width"), 10); 42 42 padding_top = parseInt(parent.css("padding-top"), 10); 43 43 padding_bottom = parseInt(parent.css("padding-bottom"), 10); 44 44 parent_top = parent.offset().top + border_top + padding_top; 45 45 parent_height = parent.height();46 -1 top = elm.offset().top - parseInt(elm.css("margin-top"), 10);47 -1 return height = elm.outerHeight(true);-1 46 sizing_elm = elm.is(".is_stuck") ? spacer : elm; -1 47 top = sizing_elm.offset().top - parseInt(sizing_elm.css("margin-top"), 10); -1 48 return height = sizing_elm.outerHeight(true); 48 49 }; 49 50 recalc(); 50 51 if (height === parent_height) { @@ -55,6 +56,7 @@ 55 56 width: elm.outerWidth(true), 56 57 height: height, 57 58 display: elm.css("display"), -1 59 "vertical-align": elm.css("vertical-align"), 58 60 float: float 59 61 }); 60 62 fixed = false;
diff --git a/site/www/src/jquery.sticky-kit.min.js b/site/www/src/jquery.sticky-kit.min.js
@@ -1,7 +1,7 @@ 1 1 /* 2 2 Sticky-kit v0.0.1 | WTFPL | Leaf Corcoran 2013 | http://leafo.net 3 3 */4 -1 (function(){var g,s;g=this.jQuery;s=g(window);g.fn.stick_in_parent=function(e){var t,c,p,A,k,B;null==e&&(e={});p=e.sticky_class;t=e.inner_scrolling;c=e.parent;null==c&&(c=void 0);null==t&&(t=!0);null==p&&(p="is_stuck");A=function(a,e,k,u,x,l){var n,q,f,v,b,d,y,z,r,w;d=a.parent();null!=c&&(d=d.closest(c));if(!d.length)throw"failed to find stick parent";y=function(){var b,f;b=parseInt(d.css("border-top-width"),10);f=parseInt(d.css("padding-top"),10);e=parseInt(d.css("padding-bottom"),10);k=d.offset().top+5 -1 b+f;u=d.height();x=a.offset().top-parseInt(a.css("margin-top"),10);return l=a.outerHeight(!0)};y();if(l!==u)return f=a.css("float"),r=g("<div />").css({width:a.outerWidth(!0),height:l,display:a.css("display"),"float":f}),n=q=!1,v=void 0,b=0,z=!1,w=function(){var h,g,m,c;m=s.scrollTop();null!=v&&(g=m-v);v=m;q?(c=m+l+b>u+k,n&&!c&&(n=!1,a.css({position:"fixed",bottom:"",top:0}).trigger("sticky_kit:unbottom")),m<x&&(q=!1,b=0,"left"!==f&&"right"!==f||a.insertAfter(r),r.detach(),h={position:""},z&&(h.width=6 -1 ""),a.css(h).removeClass(p).trigger("sticky_kit:unstick")),t&&(h=s.height(),l>h&&!n&&(b-=g,b=Math.max(h-l,b),b=Math.min(0,b),a.css({top:b+"px"})))):m>x&&(q=!0,h={position:"fixed",top:b},"none"===f&&"block"===a.css("display")&&(h.width=a.width()+"px",z=!0),a.css(h).addClass(p).after(r),"left"!==f&&"right"!==f||r.append(a),a.trigger("sticky_kit:stick"));if(q&&(null==c&&(c=m+l+b>u+k),!n&&c))return n=!0,"static"===d.css("position")&&d.css({position:"relative"}),a.css({position:"absolute",bottom:e,top:""}).trigger("sticky_kit:bottom")},7 -1 s.on("scroll",w),setTimeout(w,0),g(document.body).on("sticky_kit:recalc",function(){y();return w()})};k=0;for(B=this.length;k<B;k++)e=this[k],A(g(e));return this}}).call(this);-1 4 (function(){var g,s;g=this.jQuery;s=g(window);g.fn.stick_in_parent=function(f){var t,d,q,A,h,B;null==f&&(f={});q=f.sticky_class;t=f.inner_scrolling;d=f.parent;null==d&&(d=void 0);null==t&&(t=!0);null==q&&(q="is_stuck");A=function(a,f,h,u,x,k){var n,r,l,v,c,e,y,z,p,w;e=a.parent();null!=d&&(e=e.closest(d));if(!e.length)throw"failed to find stick parent";y=function(){var b,c;b=parseInt(e.css("border-top-width"),10);c=parseInt(e.css("padding-top"),10);f=parseInt(e.css("padding-bottom"),10);h=e.offset().top+ -1 5 b+c;u=e.height();b=a.is(".is_stuck")?p:a;x=b.offset().top-parseInt(b.css("margin-top"),10);return k=b.outerHeight(!0)};y();if(k!==u)return l=a.css("float"),p=g("<div />").css({width:a.outerWidth(!0),height:k,display:a.css("display"),"vertical-align":a.css("vertical-align"),float:l}),n=r=!1,v=void 0,c=0,z=!1,w=function(){var b,g,m,d;m=s.scrollTop();null!=v&&(g=m-v);v=m;r?(d=m+k+c>u+h,n&&!d&&(n=!1,a.css({position:"fixed",bottom:"",top:0}).trigger("sticky_kit:unbottom")),m<x&&(r=!1,c=0,"left"!==l&&"right"!== -1 6 l||a.insertAfter(p),p.detach(),b={position:""},z&&(b.width=""),a.css(b).removeClass(q).trigger("sticky_kit:unstick")),t&&(b=s.height(),k>b&&!n&&(c-=g,c=Math.max(b-k,c),c=Math.min(0,c),a.css({top:c+"px"})))):m>x&&(r=!0,b={position:"fixed",top:c},"none"===l&&"block"===a.css("display")&&(b.width=a.width()+"px",z=!0),a.css(b).addClass(q).after(p),"left"!==l&&"right"!==l||p.append(a),a.trigger("sticky_kit:stick"));if(r&&(null==d&&(d=m+k+c>u+h),!n&&d))return n=!0,"static"===e.css("position")&&e.css({position:"relative"}), -1 7 a.css({position:"absolute",bottom:f,top:""}).trigger("sticky_kit:bottom")},s.on("scroll",w),setTimeout(w,0),g(document.body).on("sticky_kit:recalc",function(){y();return w()})};h=0;for(B=this.length;h<B;h++)f=this[h],A(g(f));return this}}).call(this);