element-sticky
Version:
实现类似position:sticky效果,支持top,bottom
2 lines • 27.2 kB
JavaScript
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define("ElementSticky",[],e):"object"==typeof exports?exports.ElementSticky=e():t.ElementSticky=e()}(window,(function(){return function(t){var e={};function o(n){if(e[n])return e[n].exports;var r=e[n]={i:n,l:!1,exports:{}};return t[n].call(r.exports,r,r.exports,o),r.l=!0,r.exports}return o.m=t,o.c=e,o.d=function(t,e,n){o.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:n})},o.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},o.t=function(t,e){if(1&e&&(t=o(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var n=Object.create(null);if(o.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var r in t)o.d(n,r,function(e){return t[e]}.bind(null,r));return n},o.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return o.d(e,"a",e),e},o.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},o.p="",o(o.s=1)}([function(t,e,o){"use strict";(function(t){var o=function(){if("undefined"!=typeof Map)return Map;function t(t,e){var o=-1;return t.some((function(t,n){return t[0]===e&&(o=n,!0)})),o}return function(){function e(){this.__entries__=[]}return Object.defineProperty(e.prototype,"size",{get:function(){return this.__entries__.length},enumerable:!0,configurable:!0}),e.prototype.get=function(e){var o=t(this.__entries__,e),n=this.__entries__[o];return n&&n[1]},e.prototype.set=function(e,o){var n=t(this.__entries__,e);~n?this.__entries__[n][1]=o:this.__entries__.push([e,o])},e.prototype.delete=function(e){var o=this.__entries__,n=t(o,e);~n&&o.splice(n,1)},e.prototype.has=function(e){return!!~t(this.__entries__,e)},e.prototype.clear=function(){this.__entries__.splice(0)},e.prototype.forEach=function(t,e){void 0===e&&(e=null);for(var o=0,n=this.__entries__;o<n.length;o++){var r=n[o];t.call(e,r[1],r[0])}},e}()}(),n="undefined"!=typeof window&&"undefined"!=typeof document&&window.document===document,r=void 0!==t&&t.Math===Math?t:"undefined"!=typeof self&&self.Math===Math?self:"undefined"!=typeof window&&window.Math===Math?window:Function("return this")(),i="function"==typeof requestAnimationFrame?requestAnimationFrame.bind(r):function(t){return setTimeout((function(){return t(Date.now())}),1e3/60)};var s=["top","right","bottom","left","width","height","size","weight"],l="undefined"!=typeof MutationObserver,c=function(){function t(){this.connected_=!1,this.mutationEventsAdded_=!1,this.mutationsObserver_=null,this.observers_=[],this.onTransitionEnd_=this.onTransitionEnd_.bind(this),this.refresh=function(t,e){var o=!1,n=!1,r=0;function s(){o&&(o=!1,t()),n&&c()}function l(){i(s)}function c(){var t=Date.now();if(o){if(t-r<2)return;n=!0}else o=!0,n=!1,setTimeout(l,e);r=t}return c}(this.refresh.bind(this),20)}return t.prototype.addObserver=function(t){~this.observers_.indexOf(t)||this.observers_.push(t),this.connected_||this.connect_()},t.prototype.removeObserver=function(t){var e=this.observers_,o=e.indexOf(t);~o&&e.splice(o,1),!e.length&&this.connected_&&this.disconnect_()},t.prototype.refresh=function(){this.updateObservers_()&&this.refresh()},t.prototype.updateObservers_=function(){var t=this.observers_.filter((function(t){return t.gatherActive(),t.hasActive()}));return t.forEach((function(t){return t.broadcastActive()})),t.length>0},t.prototype.connect_=function(){n&&!this.connected_&&(document.addEventListener("transitionend",this.onTransitionEnd_),window.addEventListener("resize",this.refresh),l?(this.mutationsObserver_=new MutationObserver(this.refresh),this.mutationsObserver_.observe(document,{attributes:!0,childList:!0,characterData:!0,subtree:!0})):(document.addEventListener("DOMSubtreeModified",this.refresh),this.mutationEventsAdded_=!0),this.connected_=!0)},t.prototype.disconnect_=function(){n&&this.connected_&&(document.removeEventListener("transitionend",this.onTransitionEnd_),window.removeEventListener("resize",this.refresh),this.mutationsObserver_&&this.mutationsObserver_.disconnect(),this.mutationEventsAdded_&&document.removeEventListener("DOMSubtreeModified",this.refresh),this.mutationsObserver_=null,this.mutationEventsAdded_=!1,this.connected_=!1)},t.prototype.onTransitionEnd_=function(t){var e=t.propertyName,o=void 0===e?"":e;s.some((function(t){return!!~o.indexOf(t)}))&&this.refresh()},t.getInstance=function(){return this.instance_||(this.instance_=new t),this.instance_},t.instance_=null,t}(),u=function(t,e){for(var o=0,n=Object.keys(e);o<n.length;o++){var r=n[o];Object.defineProperty(t,r,{value:e[r],enumerable:!1,writable:!1,configurable:!0})}return t},a=function(t){return t&&t.ownerDocument&&t.ownerDocument.defaultView||r},h=g(0,0,0,0);function d(t){return parseFloat(t)||0}function p(t){for(var e=[],o=1;o<arguments.length;o++)e[o-1]=arguments[o];return e.reduce((function(e,o){return e+d(t["border-"+o+"-width"])}),0)}function f(t){var e=t.clientWidth,o=t.clientHeight;if(!e&&!o)return h;var n=a(t).getComputedStyle(t),r=function(t){for(var e={},o=0,n=["top","right","bottom","left"];o<n.length;o++){var r=n[o],i=t["padding-"+r];e[r]=d(i)}return e}(n),i=r.left+r.right,s=r.top+r.bottom,l=d(n.width),c=d(n.height);if("border-box"===n.boxSizing&&(Math.round(l+i)!==e&&(l-=p(n,"left","right")+i),Math.round(c+s)!==o&&(c-=p(n,"top","bottom")+s)),!function(t){return t===a(t).document.documentElement}(t)){var u=Math.round(l+i)-e,f=Math.round(c+s)-o;1!==Math.abs(u)&&(l-=u),1!==Math.abs(f)&&(c-=f)}return g(r.left,r.top,l,c)}var _="undefined"!=typeof SVGGraphicsElement?function(t){return t instanceof a(t).SVGGraphicsElement}:function(t){return t instanceof a(t).SVGElement&&"function"==typeof t.getBBox};function b(t){return n?_(t)?function(t){var e=t.getBBox();return g(0,0,e.width,e.height)}(t):f(t):h}function g(t,e,o,n){return{x:t,y:e,width:o,height:n}}var m=function(){function t(t){this.broadcastWidth=0,this.broadcastHeight=0,this.contentRect_=g(0,0,0,0),this.target=t}return t.prototype.isActive=function(){var t=b(this.target);return this.contentRect_=t,t.width!==this.broadcastWidth||t.height!==this.broadcastHeight},t.prototype.broadcastRect=function(){var t=this.contentRect_;return this.broadcastWidth=t.width,this.broadcastHeight=t.height,t},t}(),y=function(t,e){var o,n,r,i,s,l,c,a=(n=(o=e).x,r=o.y,i=o.width,s=o.height,l="undefined"!=typeof DOMRectReadOnly?DOMRectReadOnly:Object,c=Object.create(l.prototype),u(c,{x:n,y:r,width:i,height:s,top:r,right:n+i,bottom:s+r,left:n}),c);u(this,{target:t,contentRect:a})},v=function(){function t(t,e,n){if(this.activeObservations_=[],this.observations_=new o,"function"!=typeof t)throw new TypeError("The callback provided as parameter 1 is not a function.");this.callback_=t,this.controller_=e,this.callbackCtx_=n}return t.prototype.observe=function(t){if(!arguments.length)throw new TypeError("1 argument required, but only 0 present.");if("undefined"!=typeof Element&&Element instanceof Object){if(!(t instanceof a(t).Element))throw new TypeError('parameter 1 is not of type "Element".');var e=this.observations_;e.has(t)||(e.set(t,new m(t)),this.controller_.addObserver(this),this.controller_.refresh())}},t.prototype.unobserve=function(t){if(!arguments.length)throw new TypeError("1 argument required, but only 0 present.");if("undefined"!=typeof Element&&Element instanceof Object){if(!(t instanceof a(t).Element))throw new TypeError('parameter 1 is not of type "Element".');var e=this.observations_;e.has(t)&&(e.delete(t),e.size||this.controller_.removeObserver(this))}},t.prototype.disconnect=function(){this.clearActive(),this.observations_.clear(),this.controller_.removeObserver(this)},t.prototype.gatherActive=function(){var t=this;this.clearActive(),this.observations_.forEach((function(e){e.isActive()&&t.activeObservations_.push(e)}))},t.prototype.broadcastActive=function(){if(this.hasActive()){var t=this.callbackCtx_,e=this.activeObservations_.map((function(t){return new y(t.target,t.broadcastRect())}));this.callback_.call(t,e,t),this.clearActive()}},t.prototype.clearActive=function(){this.activeObservations_.splice(0)},t.prototype.hasActive=function(){return this.activeObservations_.length>0},t}(),w="undefined"!=typeof WeakMap?new WeakMap:new o,E=function t(e){if(!(this instanceof t))throw new TypeError("Cannot call a class as a function.");if(!arguments.length)throw new TypeError("1 argument required, but only 0 present.");var o=c.getInstance(),n=new v(e,o,this);w.set(this,n)};["observe","unobserve","disconnect"].forEach((function(t){E.prototype[t]=function(){var e;return(e=w.get(this))[t].apply(e,arguments)}}));var S=void 0!==r.ResizeObserver?r.ResizeObserver:E;e.a=S}).call(this,o(3))},function(t,e,o){"use strict";o.r(e),o.d(e,"default",(function(){return S}));o(2);var n=o(0);const r=function(t){for(const e of t){const t=e.target,o=t.__resizeListeners__||[];(t.__rs_immediate__||!t.__rs_immediate__&&t.__rs_called__)&&o.length&&o.forEach(t=>{t(e)}),t.__rs_called__=!0}};function i(t){return Object.prototype.toString.call(t).slice(8,-1).toLowerCase()}function s(t){return"array"===i(t)}function l(t){return"object"==typeof t&&!function(t){return"null"===i(t)}(t)&&!s(t)}function c(t){return l(t)&&Object.getPrototypeOf(t)===Object.prototype}function u(t){return!s(t)&&/^[+-]?[0-9]\d*$|^[+-]?[0-9]\d*\.\d+$/g.test(t)}function a(t){return t===window||t===document}function h(t,e){let o=null,n=!0,r=null;return{start(){return o||(n=!1,o=setTimeout(()=>{n=!0,"function"===i(e)&&e(),r&&r()},t)),this},stop(){return o&&(clearTimeout(o),o=null,n=!0,r=null),this},untilEnd:()=>new Promise(t=>{n&&t(),r=t})}}function d(t,e=!1){const o=t.replace(/([A-Z])/g,t=>`-${t.toLowerCase()}`);return e?o.replace(/^-/,""):o}function p(t,e=!1){return t.replace(/([:\-_]+(.))/g,(t,o,n,r)=>r>=Number(e)?n.toUpperCase():n)}function f(t,e=document){if(function(t){return t instanceof HTMLElement}(t))return t;if(function(t){return"string"===i(t)}(t)){const o=e.querySelector(t);if(!o)throw new Error(`${t} not exist in the given root node`);return o}throw new TypeError("Expected HTMLElement or valid selector")}function _(t){let e;try{e=t.getBoundingClientRect()}catch(t){}return e?(e.width&&e.height||(e={top:e.top,right:e.right,bottom:e.bottom,left:e.left,width:e.right-e.left,height:e.bottom-e.top}),e):{top:0,bottom:0,left:0,right:0,width:0,height:0}}function b(t,e,o){let n=e;if(c(n)){const e=Object.entries(n).map(([t,e])=>[`${d(t)}`.trim(),`${e}`.trim()]),o=Object.fromEntries(e),r=(t.getAttribute("style")||"").split(";").map(t=>t.split(":").map(t=>`${t}`.trim())),i=Object.fromEntries(r),s=Object.entries(Object.assign(i,o)).filter(t=>!!t[0]).map(([t,e])=>`${t}:${e}`).join(";");return t.setAttribute("style",s)}return n=p(n),t.style[n]=o,t.style[n]}function g(t,e){try{return document.defaultView.getComputedStyle(t,null).getPropertyValue(d(e,!1))}catch(o){return t.style[p(e,!1)]}}function m(t){const e=t.parentNode;return e&&11===e.nodeType&&e.host?e.host:e&&e.assignedSlot?e.assignedSlot.parentNode:e}function y(t,e){let o=0;return"x"===e?o=t.offsetWidth-t.clientWidth:"y"===e&&(o=t.offsetHeight-t.clientHeight),o<2?0:o}function v(t){if(u(t))return!0;const e=`${t}`.trim(),o=/px$/;return!!o.test(e)&&u(e.replace(o,""))}function w(t,e=0){return v(t)?`${Number.parseFloat(t)+e}px`:null}function E(t,e){const[o]=t;let n=o.intersectionRatio<=1;if(!n)return!1;const{top:r,right:i,bottom:s,left:l}=e.options.style,{top:c,right:u,bottom:a,left:h}=o.boundingClientRect,{top:d,right:p,bottom:f,left:_}=o.rootBounds,{top:b,right:g,bottom:m,left:y}=o.intersectionRect;return v(r)&&(n=n&&(c<=d||b>0&&b<=d)),n&&v(l)&&(n=n&&(h<=_||y>0&&y<=_)),n&&v(s)&&(n=n&&(a>=f||m>0&&m>=f)),n&&v(i)&&(n=n&&(u>=p||g>0&&g>=p)),n}class S{constructor(t,e){this.$args={},this.$args.el=t,this.$args.options=e,this.cot()}context(){return this.destroyed?null:this}cot(){const t=this.context(),e={scroller:null,OBSAVTTFS:50,position:null,top:null,right:null,bottom:null,left:null,style:{zIndex:9},triggerFunc:E,delayInit:0,afterInited:null,observeThreshold:1,observeRootMargin:"0px",polyfill:!1,debug:!1},{el:o,options:n}=t.$args;return t.el=f(o),t.options=Object.assign({},e,n),t.options.debug&&console.log("[ElementSticky:cot]",t.options.right),v(t.options.left)?(console.warn("[ElementSticky]:temporarily not support the left-param"),!1):v(t.options.right)?(console.warn("[ElementSticky]:temporarily not support the right-param"),!1):(v(t.options.top)||v(t.options.right)||v(t.options.bottom)||v(t.options.left)||(t.options.top=0),t.isSupportCssSticky=function(){const t=document.createElement("div");return["","-webkit-","-ms-","-moz-","-o-"].some(e=>(t.style.position=`${e}sticky`,""!==t.style.position))}(),void(!t.options.polyfill&&t.isSupportCssSticky||(t.delayExeRes&&t.delayExeRes.stop(),t.delayExeRes=h(t.options.delayInit,t.init.bind(t)),t.delayExeRes.start())))}init(){const t=this.context();if(t._inited)return;if(t.options.debug&&console.log("[ElementSticky:init]"),t.unobserve(),t.elOriginStyle=t.el.getAttribute("style"),t.elParentNode=m(t.el),t.options.scroller?t.elScroller=a(t.options.scroller)||null===t.options.scroller?null:f(t.options.scroller):t.elScroller=function(t){let e=m(t);for(;e;){if(m(e)===document){e=document;break}if(["scroll","auto","overlay"].includes(g(e,"overflow")))break;e=m(e)}return e}(t.el),a(t.elScroller)&&(t.elScroller=null),t.elClosestPositionParent=function(t){let e=m(t);for(;e&&m(e)!==document&&!["relative","absolute","fixed","sticky"].includes(g(e,"position"));)e=m(e);return e}(t.el),t.elScroller&&t.elClosestPositionParent&&!function(t,e){let o=e;for(;o;){if(o===t)return!0;o=m(o)}return!1}(t.elScroller,t.elClosestPositionParent)&&(b(t.elScroller,"position","relative"),t.elClosestPositionParent=t.elScroller),t.fakeViewportRectEl=document.querySelector("[data-el-fake-rect-el]"),["absolute","fixed"].includes(t.options.position))t.options.style.position=t.options.position;else if(t.options.style.position=null===t.elScroller?"fixed":"absolute",t.elScroller&&"absolute"===t.options.style.position){const e=t.getViewportRect(),o=t.elScroller.clientHeight,n=t.elScroller.clientWidth,r=e.height-o,i=e.width-n;c(t.options.OBSAVTTFS)?(r<t.options.OBSAVTTFS.height||i<t.options.OBSAVTTFS.width)&&(t.options.style.position="fixed"):(r<t.options.OBSAVTTFS||i<t.options.OBSAVTTFS)&&(t.options.style.position="fixed")}t.stickyByFixed="fixed"===t.options.style.position,t.stickyByAbsolute="absolute"===t.options.style.position;let{top:e,left:o,right:n,bottom:r}=t.options;const i=t.getScrollerRect(),{marginTop:s,marginRight:l,marginBottom:u,marginLeft:h}=document.defaultView.getComputedStyle(t.el);e=w(e,(t.stickyByFixed?i.top:0)-Number.parseFloat(s)),o=w(o,(t.stickyByFixed?i.left:0)-Number.parseFloat(h)),n=w(n,(t.stickyByFixed?i.right:0)-Number.parseFloat(l)),r=w(r,(t.stickyByFixed?document.documentElement.clientHeight-i.bottom:0)-Number.parseFloat(u)),t.options.style.top=e,t.options.style.left=o,t.options.style.right=n,t.options.style.bottom=r,function(t){const{top:e,right:o,bottom:n,left:r}=t;if(v(e)&&v(n))throw new Error("can not both set top and bottom");if(v(o)&&v(r))throw new Error("can not both set left and right")}(t.options.style),t.ElBoxHolder||(t.ElBoxHolder=document.createElement("div"),t.ElBoxHolder.setAttributeNode(document.createAttribute("data-el-sticky-holder")),t.elParentNode.insertBefore(t.ElBoxHolder,t.el),t.ElBoxHolder.appendChild(t.el)),t.elScrollerListenerWrap=t.elScrollerListener.bind(t),t.observeRoot=t.elScroller,t.observeEl=t.ElBoxHolder;const{marginTop:d,marginRight:p,marginBottom:_,marginLeft:y}=t.observeRoot?document.defaultView.getComputedStyle(t.observeRoot):{marginTop:0,marginRight:0,marginBottom:0,marginLeft:0};t.options.observeRootMargin=[d,p,_,y].map(t=>v(t)?w(t):"0px").join(" "),t.initObserver(),"function"==typeof t.options.afterInited&&t.options.afterInited(t),t.options.debug&&console.log("ElementSticky:inited",t),t._inited=!0}getViewportRect(){const t=this.context();return t.fakeViewportRectEl||(t.fakeViewportRectEl=document.createElement("div"),t.fakeViewportRectEl.setAttributeNode(document.createAttribute("data-el-fake-rect-el")),b(t.fakeViewportRectEl,{zIndex:-1,position:"fixed",left:0,top:0,right:0,bottom:0}),document.body.appendChild(t.fakeViewportRectEl)),_(t.fakeViewportRectEl)}getScrollerRect(){const t=this.context();return null===t.elScroller?t.getViewportRect():_(t.elScroller)}elScrollerListener(){const t=this.context();t.options.debug&&console.log("[ElementSticky:elScrollerListener]");let{top:e,left:o,right:n,bottom:r}=t.options.style;if(t.stickyByAbsolute&&t.elClosestPositionParent===t.elScroller)e=w(e,t.elScroller.scrollTop),o=w(o,t.elScroller.scrollLeft),n=w(n,0-t.elScroller.scrollLeft+y(t.elScroller,"x")),r=w(r,0-t.elScroller.scrollTop+y(t.elScroller,"y"));else{const i=t.getScrollerRect(),s=_(t.elClosestPositionParent);e=w(e,i.top-s.top),o=w(o,i.left-s.left),n=w(n,s.right-i.right+y(t.elScroller,"x")),r=w(r,s.bottom-i.bottom+y(t.elScroller,"y"))}const i=[["top",e],["right",n],["bottom",r],["left",o]].filter(({1:t})=>!!t);if(1===i.length)b(t.el,i[0][0],i[0][1]);else if(i.length>1){const e={};i.forEach(([t,o])=>{e[t]=o}),b(t.el,e)}}setElBoxHolderStyles(){const t=this.context();if(t.ElBoxHolder){const{position:e,display:o,margin:n,marginTop:r,marginRight:i,marginBottom:s,marginLeft:l}=document.defaultView.getComputedStyle(t.el),{width:c,height:u}=_(t.el);b(t.ElBoxHolder,{width:`${c}px`,height:`${u}px`,position:e,display:o,margin:n,marginTop:r,marginRight:i,marginBottom:s,marginLeft:l})}}setElStickyStyles(){const t=this.context();b(t.el,t.options.style)}unobserve(){const t=this.context();t.options.debug&&console.log("[ElementSticky:unobserve]"),t.observer&&(t.observer.unobserve(t.observeEl),t.observer.disconnect(),t.observer=null),t.unsticky()}initObserver(){const t=this.context();t.options.debug&&console.log("[ElementSticky:initObserver]"),t.observer=new IntersectionObserver(t.observeCallback.bind(t),{root:t.observeRoot,rootMargin:t.options.observeRootMargin,threshold:t.options.observeThreshold}),t.observer.observe(t.observeEl)}observeCallback(t){const e=this.context();e.options.debug&&console.log("[ElementSticky:observeCallback]",t);let o=!1;"function"==typeof e.options.triggerFunc&&(o=e.options.triggerFunc(t,e)),o?e.sticky():e.unsticky()}sticky(){const t=this.context();var e,o,i,s;t.unsticky(),t.options.debug&&console.log("[ElementSticky:sticky]"),!t.stickyed&&t.elParentNode&&t.ElBoxHolder&&(t.setElBoxHolderStyles(),t.setElStickyStyles(),t.elScroller&&t.stickyByAbsolute&&(t.elScrollerListener(),e=t.elScroller,o="scroll",i=t.elScrollerListenerWrap,s={passive:!0},e.addEventListener(o,i,s),function(t,e,o=!0){t.__resizeListeners__||(t.__resizeListeners__=[],t.__rs_immediate__=o,t.__ro__=new n.a(r),t.__ro__.observe(t)),-1===t.__resizeListeners__.indexOf(e)&&t.__resizeListeners__.push(e)}(t.elScroller,t.elScrollerListenerWrap,!1)),t.stickyed=!0)}unsticky(){const t=this.context();var e,o;t.options.debug&&console.log("[ElementSticky:unsticky]"),t.stickyed&&t.elParentNode&&t.ElBoxHolder&&(t.elScroller&&(!function(t,e,o,n=!1){t.removeEventListener(e,o,n)}(t.elScroller,"scroll",t.elScrollerListenerWrap),e=t.elScroller,o=t.elScrollerListenerWrap,e&&e.__resizeListeners__&&(e.__resizeListeners__.splice(e.__resizeListeners__.indexOf(o),1),e.__resizeListeners__.length||(e.__ro__.disconnect(),e.__ro__=null,e.__resizeListeners__=null,e.__rs_immediate__=null,e.__rs_called__=null))),t.el.setAttribute("style",t.elOriginStyle||""),t.ElBoxHolder.setAttribute("style",""),t.stickyed=!1)}destroy(){const t=this.context();t.options.debug&&console.log("[ElementSticky:destroy]"),t.delayExeRes&&t.delayExeRes.stop(),t.unobserve(),t.elParentNode&&(t.elParentNode.insertBefore(t.el,t.ElBoxHolder),t.elParentNode.removeChild(t.ElBoxHolder)),Object.keys(t).forEach(e=>{t[e]=null}),Object.setPrototypeOf(t,null),t.destroyed=!0}}},function(t,e){!function(){"use strict";if("object"==typeof window)if("IntersectionObserver"in window&&"IntersectionObserverEntry"in window&&"intersectionRatio"in window.IntersectionObserverEntry.prototype)"isIntersecting"in window.IntersectionObserverEntry.prototype||Object.defineProperty(window.IntersectionObserverEntry.prototype,"isIntersecting",{get:function(){return this.intersectionRatio>0}});else{var t=window.document,e=[];n.prototype.THROTTLE_TIMEOUT=100,n.prototype.POLL_INTERVAL=null,n.prototype.USE_MUTATION_OBSERVER=!0,n.prototype.observe=function(t){if(!this._observationTargets.some((function(e){return e.element==t}))){if(!t||1!=t.nodeType)throw new Error("target must be an Element");this._registerInstance(),this._observationTargets.push({element:t,entry:null}),this._monitorIntersections(),this._checkForIntersections()}},n.prototype.unobserve=function(t){this._observationTargets=this._observationTargets.filter((function(e){return e.element!=t})),this._observationTargets.length||(this._unmonitorIntersections(),this._unregisterInstance())},n.prototype.disconnect=function(){this._observationTargets=[],this._unmonitorIntersections(),this._unregisterInstance()},n.prototype.takeRecords=function(){var t=this._queuedEntries.slice();return this._queuedEntries=[],t},n.prototype._initThresholds=function(t){var e=t||[0];return Array.isArray(e)||(e=[e]),e.sort().filter((function(t,e,o){if("number"!=typeof t||isNaN(t)||t<0||t>1)throw new Error("threshold must be a number between 0 and 1 inclusively");return t!==o[e-1]}))},n.prototype._parseRootMargin=function(t){var e=(t||"0px").split(/\s+/).map((function(t){var e=/^(-?\d*\.?\d+)(px|%)$/.exec(t);if(!e)throw new Error("rootMargin must be specified in pixels or percent");return{value:parseFloat(e[1]),unit:e[2]}}));return e[1]=e[1]||e[0],e[2]=e[2]||e[0],e[3]=e[3]||e[1],e},n.prototype._monitorIntersections=function(){this._monitoringIntersections||(this._monitoringIntersections=!0,this.POLL_INTERVAL?this._monitoringInterval=setInterval(this._checkForIntersections,this.POLL_INTERVAL):(r(window,"resize",this._checkForIntersections,!0),r(t,"scroll",this._checkForIntersections,!0),this.USE_MUTATION_OBSERVER&&"MutationObserver"in window&&(this._domObserver=new MutationObserver(this._checkForIntersections),this._domObserver.observe(t,{attributes:!0,childList:!0,characterData:!0,subtree:!0}))))},n.prototype._unmonitorIntersections=function(){this._monitoringIntersections&&(this._monitoringIntersections=!1,clearInterval(this._monitoringInterval),this._monitoringInterval=null,i(window,"resize",this._checkForIntersections,!0),i(t,"scroll",this._checkForIntersections,!0),this._domObserver&&(this._domObserver.disconnect(),this._domObserver=null))},n.prototype._checkForIntersections=function(){var t=this._rootIsInDom(),e=t?this._getRootRect():{top:0,bottom:0,left:0,right:0,width:0,height:0};this._observationTargets.forEach((function(n){var r=n.element,i=s(r),l=this._rootContainsTarget(r),c=n.entry,u=t&&l&&this._computeTargetAndRootIntersection(r,e),a=n.entry=new o({time:window.performance&&performance.now&&performance.now(),target:r,boundingClientRect:i,rootBounds:e,intersectionRect:u});c?t&&l?this._hasCrossedThreshold(c,a)&&this._queuedEntries.push(a):c&&c.isIntersecting&&this._queuedEntries.push(a):this._queuedEntries.push(a)}),this),this._queuedEntries.length&&this._callback(this.takeRecords(),this)},n.prototype._computeTargetAndRootIntersection=function(e,o){if("none"!=window.getComputedStyle(e).display){for(var n,r,i,l,u,a,h,d,p=s(e),f=c(e),_=!1;!_;){var b=null,g=1==f.nodeType?window.getComputedStyle(f):{};if("none"==g.display)return;if(f==this.root||f==t?(_=!0,b=o):f!=t.body&&f!=t.documentElement&&"visible"!=g.overflow&&(b=s(f)),b&&(n=b,r=p,i=void 0,l=void 0,u=void 0,a=void 0,h=void 0,d=void 0,i=Math.max(n.top,r.top),l=Math.min(n.bottom,r.bottom),u=Math.max(n.left,r.left),a=Math.min(n.right,r.right),d=l-i,!(p=(h=a-u)>=0&&d>=0&&{top:i,bottom:l,left:u,right:a,width:h,height:d})))break;f=c(f)}return p}},n.prototype._getRootRect=function(){var e;if(this.root)e=s(this.root);else{var o=t.documentElement,n=t.body;e={top:0,left:0,right:o.clientWidth||n.clientWidth,width:o.clientWidth||n.clientWidth,bottom:o.clientHeight||n.clientHeight,height:o.clientHeight||n.clientHeight}}return this._expandRectByRootMargin(e)},n.prototype._expandRectByRootMargin=function(t){var e=this._rootMarginValues.map((function(e,o){return"px"==e.unit?e.value:e.value*(o%2?t.width:t.height)/100})),o={top:t.top-e[0],right:t.right+e[1],bottom:t.bottom+e[2],left:t.left-e[3]};return o.width=o.right-o.left,o.height=o.bottom-o.top,o},n.prototype._hasCrossedThreshold=function(t,e){var o=t&&t.isIntersecting?t.intersectionRatio||0:-1,n=e.isIntersecting?e.intersectionRatio||0:-1;if(o!==n)for(var r=0;r<this.thresholds.length;r++){var i=this.thresholds[r];if(i==o||i==n||i<o!=i<n)return!0}},n.prototype._rootIsInDom=function(){return!this.root||l(t,this.root)},n.prototype._rootContainsTarget=function(e){return l(this.root||t,e)},n.prototype._registerInstance=function(){e.indexOf(this)<0&&e.push(this)},n.prototype._unregisterInstance=function(){var t=e.indexOf(this);-1!=t&&e.splice(t,1)},window.IntersectionObserver=n,window.IntersectionObserverEntry=o}function o(t){this.time=t.time,this.target=t.target,this.rootBounds=t.rootBounds,this.boundingClientRect=t.boundingClientRect,this.intersectionRect=t.intersectionRect||{top:0,bottom:0,left:0,right:0,width:0,height:0},this.isIntersecting=!!t.intersectionRect;var e=this.boundingClientRect,o=e.width*e.height,n=this.intersectionRect,r=n.width*n.height;this.intersectionRatio=o?Number((r/o).toFixed(4)):this.isIntersecting?1:0}function n(t,e){var o,n,r,i=e||{};if("function"!=typeof t)throw new Error("callback must be a function");if(i.root&&1!=i.root.nodeType)throw new Error("root must be an Element");this._checkForIntersections=(o=this._checkForIntersections.bind(this),n=this.THROTTLE_TIMEOUT,r=null,function(){r||(r=setTimeout((function(){o(),r=null}),n))}),this._callback=t,this._observationTargets=[],this._queuedEntries=[],this._rootMarginValues=this._parseRootMargin(i.rootMargin),this.thresholds=this._initThresholds(i.threshold),this.root=i.root||null,this.rootMargin=this._rootMarginValues.map((function(t){return t.value+t.unit})).join(" ")}function r(t,e,o,n){"function"==typeof t.addEventListener?t.addEventListener(e,o,n||!1):"function"==typeof t.attachEvent&&t.attachEvent("on"+e,o)}function i(t,e,o,n){"function"==typeof t.removeEventListener?t.removeEventListener(e,o,n||!1):"function"==typeof t.detatchEvent&&t.detatchEvent("on"+e,o)}function s(t){var e;try{e=t.getBoundingClientRect()}catch(t){}return e?(e.width&&e.height||(e={top:e.top,right:e.right,bottom:e.bottom,left:e.left,width:e.right-e.left,height:e.bottom-e.top}),e):{top:0,bottom:0,left:0,right:0,width:0,height:0}}function l(t,e){for(var o=e;o;){if(o==t)return!0;o=c(o)}return!1}function c(t){var e=t.parentNode;return e&&11==e.nodeType&&e.host?e.host:e&&e.assignedSlot?e.assignedSlot.parentNode:e}}()},function(t,e){var o;o=function(){return this}();try{o=o||new Function("return this")()}catch(t){"object"==typeof window&&(o=window)}t.exports=o}]).default}));
//# sourceMappingURL=ElementSticky.js.map