- commit
- 323fddedaa0018b5dfe2828a108dc7ac48038c50
- parent
- 8b77aa0e5ca868dcbb830f8d1dae8a0bfc8b9ad3
- Author
- leaf corcoran <leafot@gmail.com>
- Date
- 2014-11-13 09:18
add recalc_every option
Diffstat
| M | jquery.sticky-kit.coffee | 9 | +++++++++ |
| M | jquery.sticky-kit.js | 17 | +++++++++++++---- |
| M | jquery.sticky-kit.min.js | 11 | ++++++----- |
3 files changed, 28 insertions, 9 deletions
diff --git a/jquery.sticky-kit.coffee b/jquery.sticky-kit.coffee
@@ -9,6 +9,7 @@ $.fn.stick_in_parent = (opts={}) ->
9 9 {
10 10 sticky_class
11 11 inner_scrolling
-1 12 recalc_every
12 13 parent: parent_selector
13 14 offset_top
14 15 spacer: manual_spacer
@@ -87,7 +88,15 @@ $.fn.stick_in_parent = (opts={}) ->
87 88 last_pos = undefined
88 89 offset = offset_top
89 90
-1 91 recalc_counter = recalc_every
-1 92
90 93 tick = ->
-1 94 if recalc_counter?
-1 95 recalc_counter -= 1
-1 96 if recalc_counter <= 0
-1 97 recalc_counter = recalc_every
-1 98 recalc()
-1 99
91 100 scroll = win.scrollTop()
92 101 if last_pos?
93 102 delta = scroll - last_pos
diff --git a/jquery.sticky-kit.js b/jquery.sticky-kit.js
@@ -1,4 +1,4 @@1 -1 // Generated by CoffeeScript 1.8.0-1 1 // Generated by CoffeeScript 1.7.1 2 2 3 3 /** 4 4 @license Sticky-kit v1.0.5 | WTFPL | Leaf Corcoran 2014 | http://leafo.net @@ -12,11 +12,11 @@ 12 12 win = $(window); 13 13 14 14 $.fn.stick_in_parent = function(opts) {15 -1 var elm, enable_bottoming, inner_scrolling, manual_spacer, offset_top, parent_selector, sticky_class, _fn, _i, _len;-1 15 var elm, enable_bottoming, inner_scrolling, manual_spacer, offset_top, parent_selector, recalc_every, sticky_class, _fn, _i, _len; 16 16 if (opts == null) { 17 17 opts = {}; 18 18 }19 -1 sticky_class = opts.sticky_class, inner_scrolling = opts.inner_scrolling, parent_selector = opts.parent, offset_top = opts.offset_top, manual_spacer = opts.spacer, enable_bottoming = opts.bottoming;-1 19 sticky_class = opts.sticky_class, inner_scrolling = opts.inner_scrolling, recalc_every = opts.recalc_every, parent_selector = opts.parent, offset_top = opts.offset_top, manual_spacer = opts.spacer, enable_bottoming = opts.bottoming; 20 20 if (offset_top == null) { 21 21 offset_top = 0; 22 22 } @@ -33,7 +33,7 @@ 33 33 enable_bottoming = true; 34 34 } 35 35 _fn = function(elm, padding_bottom, parent_top, parent_height, top, height, el_float) {36 -1 var bottomed, detach, fixed, last_pos, offset, parent, recalc, recalc_and_tick, spacer, tick;-1 36 var bottomed, detach, fixed, last_pos, offset, parent, recalc, recalc_and_tick, recalc_counter, spacer, tick; 37 37 if (elm.data("sticky_kit")) { 38 38 return; 39 39 } @@ -53,6 +53,7 @@ 53 53 } 54 54 recalc = function() { 55 55 var border_top, padding_top, restore; -1 56 console.log("recalc"); 56 57 border_top = parseInt(parent.css("border-top-width"), 10); 57 58 padding_top = parseInt(parent.css("padding-top"), 10); 58 59 padding_bottom = parseInt(parent.css("padding-bottom"), 10); @@ -95,8 +96,16 @@ 95 96 } 96 97 last_pos = void 0; 97 98 offset = offset_top; -1 99 recalc_counter = recalc_every; 98 100 tick = function() { 99 101 var css, delta, scroll, will_bottom, win_height; -1 102 if (recalc_counter != null) { -1 103 recalc_counter -= 1; -1 104 if (recalc_counter <= 0) { -1 105 recalc_counter = recalc_every; -1 106 recalc(); -1 107 } -1 108 } 100 109 scroll = win.scrollTop(); 101 110 if (last_pos != null) { 102 111 delta = scroll - last_pos;
diff --git a/jquery.sticky-kit.min.js b/jquery.sticky-kit.min.js
@@ -1,8 +1,9 @@ 1 1 /* 2 2 Sticky-kit v1.0.5 | WTFPL | Leaf Corcoran 2014 | http://leafo.net 3 3 */4 -1 (function(){var k,e;k=this.jQuery||window.jQuery;e=k(window);k.fn.stick_in_parent=function(d){var v,x,n,r,h,s,D,p,E;null==d&&(d={});s=d.sticky_class;x=d.inner_scrolling;h=d.parent;r=d.offset_top;n=d.spacer;v=d.bottoming;null==r&&(r=0);null==h&&(h=void 0);null==x&&(x=!0);null==s&&(s="is_stuck");null==v&&(v=!0);D=function(a,d,p,y,A,t,q){var u,B,m,z,c,f,C,w,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=5 -1 !1;(g=null!=n?n&&a.closest(n):k("<div />"))&&g.css("position",a.css("position"));C=function(){var c,e,l;c=parseInt(f.css("border-top-width"),10);e=parseInt(f.css("padding-top"),10);d=parseInt(f.css("padding-bottom"),10);p=f.offset().top+c+e;y=f.height();m&&(u=m=!1,null==n&&(a.insertAfter(g),g.detach()),a.css({position:"",top:"",width:"",bottom:""}).removeClass(s),l=!0);A=a.offset().top-parseInt(a.css("margin-top"),10)-r;t=a.outerHeight(!0);q=a.css("float");g&&g.css({width:a.outerWidth(!0),height:t,6 -1 display:a.css("display"),"vertical-align":a.css("vertical-align"),"float":q});if(l)return b()};C();if(t!==y)return z=void 0,c=r,b=function(){var b,k,l,h;l=e.scrollTop();null!=z&&(k=l-z);z=l;m?(v&&(h=l+t+c>y+p,u&&!h&&(u=!1,a.css({position:"fixed",bottom:"",top:c}).trigger("sticky_kit:unbottom"))),l<A&&(m=!1,c=r,null==n&&("left"!==q&&"right"!==q||a.insertAfter(g),g.detach()),b={position:"",width:"",top:""},a.css(b).removeClass(s).trigger("sticky_kit:unstick")),x&&(b=e.height(),t>b&&!u&&(c-=k,c=Math.max(b-7 -1 t,c),c=Math.min(r,c),m&&a.css({top:c+"px"})))):l>A&&(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"!==q&&"right"!==q||g.append(a)),a.trigger("sticky_kit:stick"));if(m&&v&&(null==h&&(h=l+t+c>y+p),!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(){C();return b()},B=function(){e.off("touchmove",8 -1 b);e.off("scroll",b);e.off("resize",w);k(document.body).off("sticky_kit:recalc",w);a.off("sticky_kit:detach",B);a.removeData("sticky_kit");a.css({position:"",bottom:"",top:""});f.position("position","");if(m)return null==n&&("left"!==q&&"right"!==q||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",B),setTimeout(b,0)}};p=0;for(E=this.length;p<E;p++)d=this[p],D(k(d));return this}}).call(this);-1 4 (function(){var k,e;k=this.jQuery||window.jQuery;e=k(window);k.fn.stick_in_parent=function(d){var w,y,n,r,h,C,s,F,p,G;null==d&&(d={});s=d.sticky_class;y=d.inner_scrolling;C=d.recalc_every;h=d.parent;r=d.offset_top;n=d.spacer;w=d.bottoming;null==r&&(r=0);null==h&&(h=void 0);null==y&&(y=!0);null==s&&(s="is_stuck");null==w&&(w=!0);F=function(a,d,p,z,D,t,q){var u,E,m,A,c,f,B,x,v,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"; -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;console.log("recalc");c=parseInt(f.css("border-top-width"),10);e=parseInt(f.css("padding-top"),10);d=parseInt(f.css("padding-bottom"),10);p=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)-r;t=a.outerHeight(!0);q=a.css("float");g&&g.css({width:a.outerWidth(!0), -1 6 height:t,display:a.css("display"),"vertical-align":a.css("vertical-align"),"float":q});if(l)return b()};B();if(t!==z)return A=void 0,c=r,v=C,b=function(){var b,k,l,h;null!=v&&(v-=1,0>=v&&(v=C,B()));l=e.scrollTop();null!=A&&(k=l-A);A=l;m?(w&&(h=l+t+c>z+p,u&&!h&&(u=!1,a.css({position:"fixed",bottom:"",top:c}).trigger("sticky_kit:unbottom"))),l<D&&(m=!1,c=r,null==n&&("left"!==q&&"right"!==q||a.insertAfter(g),g.detach()),b={position:"",width:"",top:""},a.css(b).removeClass(s).trigger("sticky_kit:unstick")), -1 7 y&&(b=e.height(),t>b&&!u&&(c-=k,c=Math.max(b-t,c),c=Math.min(r,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"!==q&&"right"!==q||g.append(a)),a.trigger("sticky_kit:stick"));if(m&&w&&(null==h&&(h=l+t+c>z+p),!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")}, -1 8 x=function(){B();return b()},E=function(){e.off("touchmove",b);e.off("scroll",b);e.off("resize",x);k(document.body).off("sticky_kit:recalc",x);a.off("sticky_kit:detach",E);a.removeData("sticky_kit");a.css({position:"",bottom:"",top:""});f.position("position","");if(m)return null==n&&("left"!==q&&"right"!==q||a.insertAfter(g),g.remove()),a.removeClass(s)},e.on("touchmove",b),e.on("scroll",b),e.on("resize",x),k(document.body).on("sticky_kit:recalc",x),a.on("sticky_kit:detach",E),setTimeout(b,0)}};p= -1 9 0;for(G=this.length;p<G;p++)d=this[p],F(k(d));return this}}).call(this);