relatively-sticky

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

commit
6d69c8e4a5dad78d8266308deef7afaf1a7bbbaf
parent
a3bd7733220359dfcf989d188c9311ed8de703b9
Author
leaf corcoran <leafot@gmail.com>
Date
2013-11-02 01:47
prevent accidentally setting top when not fixed with inner scrolling enabled

Diffstat

M jquery.sticky-kit.coffee 7 ++++---
M jquery.sticky-kit.js 8 +++++---
M jquery.sticky-kit.min.js 8 ++++----

3 files changed, 13 insertions, 10 deletions


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

@@ -97,9 +97,10 @@ $.fn.stick_in_parent = (opts={}) ->
   97    97                 offset = Math.max win_height - height, offset
   98    98                 offset = Math.min offset_top, offset
   99    99 
  100    -1                 elm.css {
  101    -1                   top: offset + "px"
  102    -1                 }
   -1   100                 if fixed
   -1   101                   elm.css {
   -1   102                     top: offset + "px"
   -1   103                   }
  103   104 
  104   105         else
  105   106           # fixing

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

@@ -106,9 +106,11 @@
  106   106                 offset -= delta;
  107   107                 offset = Math.max(win_height - height, offset);
  108   108                 offset = Math.min(offset_top, offset);
  109    -1                 elm.css({
  110    -1                   top: offset + "px"
  111    -1                 });
   -1   109                 if (fixed) {
   -1   110                   elm.css({
   -1   111                     top: offset + "px"
   -1   112                   });
   -1   113                 }
  112   114               }
  113   115             }
  114   116           }

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

@@ -1,7 +1,7 @@
    1     1 /*
    2     2  Sticky-kit v1.0.1 | WTFPL | Leaf Corcoran 2013 | http://leafo.net
    3     3 */
    4    -1 (function(){var g,t;g=this.jQuery;t=g(window);g.fn.stick_in_parent=function(d){var u,k,e,r,B,h,C;null==d&&(d={});r=d.sticky_class;u=d.inner_scrolling;e=d.parent;k=d.offset_top;null==k&&(k=0);null==e&&(e=void 0);null==u&&(u=!0);null==r&&(r="is_stuck");B=function(a,d,h,v,y,l){var p,s,m,w,b,f,z,A,q,x;f=a.parent();null!=e&&(f=f.closest(e));if(!f.length)throw"failed to find stick parent";z=function(){var c,b;c=parseInt(f.css("border-top-width"),10);b=parseInt(f.css("padding-top"),10);d=parseInt(f.css("padding-bottom"),
    5    -1 10);h=f.offset().top+c+b;v=f.height();c=a.is(".is_stuck")?q:a;y=c.offset().top-parseInt(c.css("margin-top"),10)-k;return l=c.outerHeight(!0)};z();if(l!==v)return m=a.css("float"),q=g("<div />").css({width:a.outerWidth(!0),height:l,display:a.css("display"),"vertical-align":a.css("vertical-align"),float:m}),p=s=!1,w=void 0,b=k,A=!1,x=function(){var c,g,n,e;n=t.scrollTop();null!=w&&(g=n-w);w=n;s?(e=n+l+b>v+h,p&&!e&&(p=!1,a.css({position:"fixed",bottom:"",top:b}).trigger("sticky_kit:unbottom")),n<y&&
    6    -1 (s=!1,b=k,"left"!==m&&"right"!==m||a.insertAfter(q),q.detach(),c={position:"",top:""},A&&(c.width=""),a.css(c).removeClass(r).trigger("sticky_kit:unstick")),u&&(c=t.height(),l>c&&!p&&(b-=g,b=Math.max(c-l,b),b=Math.min(k,b),a.css({top:b+"px"})))):n>y&&(s=!0,c={position:"fixed",top:b},"none"===m&&"block"===a.css("display")&&(c.width=a.width()+"px",A=!0),a.css(c).addClass(r).after(q),"left"!==m&&"right"!==m||q.append(a),a.trigger("sticky_kit:stick"));if(s&&(null==e&&(e=n+l+b>v+h),!p&&e))return p=!0,
    7    -1 "static"===f.css("position")&&f.css({position:"relative"}),a.css({position:"absolute",bottom:d,top:""}).trigger("sticky_kit:bottom")},t.on("scroll",x),setTimeout(x,0),g(document.body).on("sticky_kit:recalc",function(){z();return x()})};h=0;for(C=this.length;h<C;h++)d=this[h],B(g(d));return this}}).call(this);
   -1     4 (function(){var g,t;g=this.jQuery;t=g(window);g.fn.stick_in_parent=function(d){var u,k,e,s,B,h,C;null==d&&(d={});s=d.sticky_class;u=d.inner_scrolling;e=d.parent;k=d.offset_top;null==k&&(k=0);null==e&&(e=void 0);null==u&&(u=!0);null==s&&(s="is_stuck");B=function(a,d,h,v,y,l){var p,q,m,w,b,f,z,A,r,x;f=a.parent();null!=e&&(f=f.closest(e));if(!f.length)throw"failed to find stick parent";z=function(){var c,b;c=parseInt(f.css("border-top-width"),10);b=parseInt(f.css("padding-top"),10);d=parseInt(f.css("padding-bottom"),
   -1     5 10);h=f.offset().top+c+b;v=f.height();c=a.is(".is_stuck")?r:a;y=c.offset().top-parseInt(c.css("margin-top"),10)-k;return l=c.outerHeight(!0)};z();if(l!==v)return m=a.css("float"),r=g("<div />").css({width:a.outerWidth(!0),height:l,display:a.css("display"),"vertical-align":a.css("vertical-align"),float:m}),p=q=!1,w=void 0,b=k,A=!1,x=function(){var c,g,n,e;n=t.scrollTop();null!=w&&(g=n-w);w=n;q?(e=n+l+b>v+h,p&&!e&&(p=!1,a.css({position:"fixed",bottom:"",top:b}).trigger("sticky_kit:unbottom")),n<y&&
   -1     6 (q=!1,b=k,"left"!==m&&"right"!==m||a.insertAfter(r),r.detach(),c={position:"",top:""},A&&(c.width=""),a.css(c).removeClass(s).trigger("sticky_kit:unstick")),u&&(c=t.height(),l>c&&!p&&(b-=g,b=Math.max(c-l,b),b=Math.min(k,b),q&&a.css({top:b+"px"})))):n>y&&(q=!0,c={position:"fixed",top:b},"none"===m&&"block"===a.css("display")&&(c.width=a.width()+"px",A=!0),a.css(c).addClass(s).after(r),"left"!==m&&"right"!==m||r.append(a),a.trigger("sticky_kit:stick"));if(q&&(null==e&&(e=n+l+b>v+h),!p&&e))return p=
   -1     7 !0,"static"===f.css("position")&&f.css({position:"relative"}),a.css({position:"absolute",bottom:d,top:""}).trigger("sticky_kit:bottom")},t.on("scroll",x),setTimeout(x,0),g(document.body).on("sticky_kit:recalc",function(){z();return x()})};h=0;for(C=this.length;h<C;h++)d=this[h],B(g(d));return this}}).call(this);