relatively-sticky

A jQuery plugin for creating smart sticky elements
git clone https://git.ce9e.org/relatively-sticky.git

commit
6d201ae98dad07263ebe7c119fc1cc4c13092a7c
parent
b6b1f733082dd5a3c0bf51e17525997495b37373
Author
Norman Chen <nchen@livongo.com>
Date
2014-12-30 07:15
support undefined/auto margin-top in IE.

Diffstat

M jquery.sticky-kit.coffee 2 +-
M jquery.sticky-kit.js 4 ++--
M jquery.sticky-kit.min.js 2 +-

3 files changed, 4 insertions, 4 deletions


diff --git a/jquery.sticky-kit.coffee b/jquery.sticky-kit.coffee

@@ -67,7 +67,7 @@ $.fn.stick_in_parent = (opts={}) ->
   67    67 
   68    68           restore = true
   69    69 
   70    -1         top = elm.offset().top - parseInt(elm.css("margin-top"), 10) - offset_top
   -1    70         top = elm.offset().top - (parseInt(elm.css("margin-top"), 10) or 0) - offset_top
   71    71 
   72    72         height = elm.outerHeight true
   73    73 

diff --git a/jquery.sticky-kit.js b/jquery.sticky-kit.js

@@ -1,4 +1,4 @@
    1    -1 // Generated by CoffeeScript 1.7.1
   -1     1 // Generated by CoffeeScript 1.8.0
    2     2 
    3     3 /**
    4     4 @license Sticky-kit v1.1.1 | WTFPL | Leaf Corcoran 2014 | http://leafo.net
@@ -76,7 +76,7 @@
   76    76           }).removeClass(sticky_class);
   77    77           restore = true;
   78    78         }
   79    -1         top = elm.offset().top - parseInt(elm.css("margin-top"), 10) - offset_top;
   -1    79         top = elm.offset().top - (parseInt(elm.css("margin-top"), 10) || 0) - offset_top;
   80    80         height = elm.outerHeight(true);
   81    81         el_float = elm.css("float");
   82    82         if (spacer) {

diff --git a/jquery.sticky-kit.min.js b/jquery.sticky-kit.min.js

@@ -2,7 +2,7 @@
    2     2  Sticky-kit v1.1.1 | WTFPL | Leaf Corcoran 2014 | http://leafo.net
    3     3 */
    4     4 (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";
    5    -1 u=m=!1;(g=null!=n?n&&a.closest(n):k("<div />"))&&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)-p,t=a.outerHeight(!0),r=a.css("float"),g&&g.css({width:a.outerWidth(!0),
   -1     5 u=m=!1;(g=null!=n?n&&a.closest(n):k("<div />"))&&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),
    6     6 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<D&&(m=!1,c=p,null==n&&("left"!==r&&"right"!==r||a.insertAfter(g),g.detach()),b={position:"",width:"",top:""},a.css(b).removeClass(s).trigger("sticky_kit:unstick")),
    7     7 y&&(b=e.height(),t+p>b&&!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")},
    8     8 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,