relatively-sticky

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

commit
7570b3c6c4181b49ef9823aabdc4a2e800a68e12
parent
bfeccbd48c7b748440dda2ac1aee6601736bab65
Author
leaf corcoran <leafot@gmail.com>
Date
2013-09-11 17:09
update docs + version bump :sunglasses:

Diffstat

M bower.json 2 +-
M jquery.sticky-kit.coffee 2 +-
M jquery.sticky-kit.js 2 +-
M jquery.sticky-kit.min.js 10 +++++-----
M site/index.html 9 ++++++++-
M site/site.moon 2 +-
M site/www/src/jquery.sticky-kit.js 22 ++++++++++++----------
M site/www/src/jquery.sticky-kit.min.js 10 +++++-----
M sticky-kit.jquery.json 2 +-

9 files changed, 35 insertions, 26 deletions


diff --git a/bower.json b/bower.json

@@ -1,6 +1,6 @@
    1     1 {
    2     2   "name": "sticky-kit",
    3    -1   "version": "1.0.0",
   -1     3   "version": "1.0.1",
    4     4   "homepage": "http://leafo.net/sticky-kit/",
    5     5   "authors": [
    6     6     "leaf corcoran <leafot@gmail.com>"

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

@@ -1,5 +1,5 @@
    1     1 ###*
    2    -1 @license Sticky-kit v0.0.1 | WTFPL | Leaf Corcoran 2013 | http://leafo.net
   -1     2 @license Sticky-kit v1.0.1 | WTFPL | Leaf Corcoran 2013 | http://leafo.net
    3     3 ###
    4     4 
    5     5 $ = @jQuery

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

@@ -1,7 +1,7 @@
    1     1 // Generated by CoffeeScript 1.4.0
    2     2 
    3     3 /**
    4    -1 @license Sticky-kit v0.0.1 | WTFPL | Leaf Corcoran 2013 | http://leafo.net
   -1     4 @license Sticky-kit v1.0.1 | WTFPL | Leaf Corcoran 2013 | http://leafo.net
    5     5 */
    6     6 
    7     7 

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

@@ -1,7 +1,7 @@
    1     1 /*
    2    -1  Sticky-kit v0.0.1 | WTFPL | Leaf Corcoran 2013 | http://leafo.net
   -1     2  Sticky-kit v1.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(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+
    5    -1 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"!==
    6    -1 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"}),
    7    -1 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);
   -1     4 (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"),
   -1     5 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&&
   -1     6 (s=!1,b=k,"left"!==m&&"right"!==m||a.insertAfter(q),q.detach(),c={position:""},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,"static"===
   -1     7 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);

diff --git a/site/index.html b/site/index.html

@@ -7,7 +7,7 @@
    7     7 
    8     8   <a href="#examples">Examples</a>
    9     9   <a href="#reference">Reference</a>
   10    -1   <a href="https://raw.github.com/leafo/sticky-kit/v1.0.0/jquery.sticky-kit.min.js" class="hidden">Download</a>
   -1    10   <a href="https://rawgithub.com/leafo/sticky-kit/v$version/jquery.sticky-kit.min.js" class="hidden">Download</a>
   11    11 </div>
   12    12 
   13    13 
@@ -160,6 +160,8 @@ following options are accepted:
  160   160   viewport. Defaults to `true` for enabled.
  161   161 * `sticky_class` -- The name of the CSS class to apply to elements when they
  162   162   have become stuck. Defaults to `"is_stuck"`.
   -1   163 * `offset_top` -- offsets the initial sticking position by of number of pixels,
   -1   164   can be either negative or positive
  163   165 
  164   166 ### Events
  165   167 
@@ -218,5 +220,10 @@ Sticky Kit works with all modern browsers, and IE7+.
  218   220 
  219   221 Note: only floated columns work in IE7.
  220   222 
   -1   223 ### Changelog
   -1   224 
   -1   225   * **v1.0.1** *Sept 11, 2013* -- Added offset_top option, fixed recaclc when items are
   -1   226     already stuck
   -1   227 
  221   228 ]]}
  222   229 

diff --git a/site/site.moon b/site/site.moon

@@ -9,7 +9,7 @@ exec = (cmd) ->
    9     9 
   10    10 site = sitegen.create_site =>
   11    11   @title = "Sticky-Kit | jQuery plugin for sticky elements"
   12    -1   @version = "1.0.0"
   -1    12   @version = "1.0.1"
   13    13 
   14    14   @full_size = exec("du -bh www/src/jquery.sticky-kit.js | cut -f 1")\lower!
   15    15   @compressed_size = exec("du -bh www/src/jquery.sticky-kit.min.js | cut -f 1")\lower!

diff --git a/site/www/src/jquery.sticky-kit.js b/site/www/src/jquery.sticky-kit.js

@@ -1,7 +1,7 @@
    1     1 // Generated by CoffeeScript 1.4.0
    2     2 
    3     3 /**
    4    -1 @license Sticky-kit v0.0.1 | WTFPL | Leaf Corcoran 2013 | http://leafo.net
   -1     4 @license Sticky-kit v1.0.1 | WTFPL | Leaf Corcoran 2013 | http://leafo.net
    5     5 */
    6     6 
    7     7 
@@ -13,11 +13,14 @@
   13    13   win = $(window);
   14    14 
   15    15   $.fn.stick_in_parent = function(opts) {
   16    -1     var elm, inner_scrolling, parent_selector, sticky_class, _fn, _i, _len;
   -1    16     var elm, inner_scrolling, offset_top, parent_selector, sticky_class, _fn, _i, _len;
   17    17     if (opts == null) {
   18    18       opts = {};
   19    19     }
   20    -1     sticky_class = opts.sticky_class, inner_scrolling = opts.inner_scrolling, parent_selector = opts.parent;
   -1    20     sticky_class = opts.sticky_class, inner_scrolling = opts.inner_scrolling, parent_selector = opts.parent, offset_top = opts.offset_top;
   -1    21     if (offset_top == null) {
   -1    22       offset_top = 0;
   -1    23     }
   21    24     if (parent_selector == null) {
   22    25       parent_selector = void 0;
   23    26     }
@@ -44,7 +47,7 @@
   44    47         parent_top = parent.offset().top + border_top + padding_top;
   45    48         parent_height = parent.height();
   46    49         sizing_elm = elm.is(".is_stuck") ? spacer : elm;
   47    -1         top = sizing_elm.offset().top - parseInt(sizing_elm.css("margin-top"), 10);
   -1    50         top = sizing_elm.offset().top - parseInt(sizing_elm.css("margin-top"), 10) - offset_top;
   48    51         return height = sizing_elm.outerHeight(true);
   49    52       };
   50    53       recalc();
@@ -62,10 +65,10 @@
   62    65       fixed = false;
   63    66       bottomed = false;
   64    67       last_pos = void 0;
   65    -1       offset = 0;
   -1    68       offset = offset_top;
   66    69       reset_width = false;
   67    70       tick = function() {
   68    -1         var before, css, delta, scroll, will_bottom, win_height;
   -1    71         var css, delta, scroll, will_bottom, win_height;
   69    72         scroll = win.scrollTop();
   70    73         if (last_pos != null) {
   71    74           delta = scroll - last_pos;
@@ -78,12 +81,12 @@
   78    81             elm.css({
   79    82               position: "fixed",
   80    83               bottom: "",
   81    -1               top: 0
   -1    84               top: offset
   82    85             }).trigger("sticky_kit:unbottom");
   83    86           }
   84    87           if (scroll < top) {
   85    88             fixed = false;
   86    -1             offset = 0;
   -1    89             offset = offset_top;
   87    90             if (float === "left" || float === "right") {
   88    91               elm.insertAfter(spacer);
   89    92             }
@@ -101,9 +104,8 @@
  101   104             if (height > win_height) {
  102   105               if (!bottomed) {
  103   106                 offset -= delta;
  104    -1                 before = offset;
  105   107                 offset = Math.max(win_height - height, offset);
  106    -1                 offset = Math.min(0, offset);
   -1   108                 offset = Math.min(offset_top, offset);
  107   109                 elm.css({
  108   110                   top: offset + "px"
  109   111                 });

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    -1  Sticky-kit v0.0.1 | WTFPL | Leaf Corcoran 2013 | http://leafo.net
   -1     2  Sticky-kit v1.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(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+
    5    -1 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"!==
    6    -1 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"}),
    7    -1 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);
   -1     4 (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"),
   -1     5 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&&
   -1     6 (s=!1,b=k,"left"!==m&&"right"!==m||a.insertAfter(q),q.detach(),c={position:""},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,"static"===
   -1     7 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);

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

@@ -1,6 +1,6 @@
    1     1 {
    2     2   "name": "sticky-kit",
    3    -1   "version": "1.0.0",
   -1     3   "version": "1.0.1",
    4     4 
    5     5   "title": "Sticky-kit",
    6     6   "homepage": "http://leafo.net/sticky-kit",