forked from PostovoyNet/jquery.airStickyBlock
-
Notifications
You must be signed in to change notification settings - Fork 0
/
jquery.airStickyBlock.min.js
1 lines (1 loc) · 1.72 KB
/
jquery.airStickyBlock.min.js
1
!function(t){t.fn.airStickyBlock=function(i){return t.airStickyBlock=function(i,e){function o(){f=t(window).height(),d=k.height(),p=k.width(),y=k.offset().top,S=u.width(),v=u.offset().top,h=i.outerHeight(!0),w=S,b=d+y-h,B=v+i.position().top,g=b-v}function a(){if(_=t(window).scrollTop()+n.offsetTop,n.debug){console.clear(),console.warn("airStickyBlock debugger \n");var e={windowHeight:{value:f},stopBlockHeight:{value:d},stopBlockWidth:{value:p},stopBlockOffset:{value:y},stickyParentOffset:{value:v},stickyParentWidth:{value:S},stickyHeight:{value:h},stickyWidth:{value:w},stickyStop:{value:b},stickyStart:{value:B},stickyAbsolute:{value:g},scrollTop:{value:_}};console.table(e)}_>=B&&b>=_?s("fixed"):"relative"!=i.css("position")&&(c(u),s("relative")),_>=B&&_>=b&&s("absolute"),_>b+h&&s("relative")}function c(t){t.removeAttr("style")}function s(t){switch(t){case"fixed":i.css({position:t,top:n.offsetTop+"px"}).removeClass("airSticky_absolute airSticky_relative").addClass("airSticky_fixed");break;case"absolute":i.css({position:t,top:g+"px"}).removeClass("airSticky_fixed airSticky_relative").addClass("airSticky_absolute");break;case"relative":i.css({position:"relative",top:"auto"}).removeClass("airSticky_fixed airSticky_absolute").addClass("airSticky_relative")}}function l(){i.css({width:w+"px"})}function r(){c(i),o(),b>B&&p>w&&(l(),a())}var n,k,u,f,d,p,y,v,S,h,w,b,B,g,_;n=t.extend({debug:!1,stopBlock:".airSticky_stop-block",offsetTop:0},e),k=t(n.stopBlock),u=i.parent(),o(),a(),l(),t(window).bind("resize.airStickyBlock scroll.airStickyBlock orientationchange.airStickyBlock",function(t){"scroll"==t.type&&b>B&&p>w?a():r()}),t(window).bind("render.airStickyBlock",function(t){r()})},this.each(function(){new t.airStickyBlock(t(this),i)})}}(jQuery);