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