@z-utils/react
Version:
zzy 工具库/react
2 lines (1 loc) • 2.41 kB
JavaScript
;var e=require("@babel/runtime/helpers/classCallCheck"),t=require("@babel/runtime/helpers/createClass"),n=require("@babel/runtime/helpers/assertThisInitialized"),r=require("@babel/runtime/helpers/inherits"),i=require("@babel/runtime/helpers/possibleConstructorReturn"),o=require("@babel/runtime/helpers/getPrototypeOf"),l=require("@babel/runtime/helpers/defineProperty"),c=require("react/jsx-runtime");function u(e){var t=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return!1}}();return function(){var n,r=o(e);if(t){var l=o(this).constructor;n=Reflect.construct(r,arguments,l)}else n=r.apply(this,arguments);return i(this,n)}}var s=function(i){r(s,i);var o=u(s);function s(t){var r;return e(this,s),r=o.call(this,t),l(n(r),"infinityScrolling",(function(e,t){var n,r=this;"IntersectionObserver"in window?new IntersectionObserver((function(e){r.props.getDataBol&&e[0].intersectionRatio&&t(r)})).observe(e):(n=function(e){var t,n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:100,r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:30,i=null,o=this;return function(){var l=+new Date,c=Array.prototype.slice.call(arguments);clearTimeout(t),i||(i=l),l-i>r?(e.apply(o,c),i=l):t=setTimeout((function(){e.apply(o,c)}),n)}}((function(){if(!r.props.getDataBol)return;(function(e){var t=arguments.length>1&&void 0!==arguments[1]&&arguments[1],n=e.getBoundingClientRect(),r=n.top,i=n.left,o=n.bottom,l=n.right,c=window,u=c.innerHeight,s=c.innerWidth;return t?(r>0&&r<u||o>0&&o<u)&&(i>0&&i<s||l>0&&l<s):r>=0&&i>=0&&o<=u&&l<=s})(e,!0)&&t(r)}),100),document.addEventListener("scroll",n));this.infinityScrolling.closeMonitor=function(){"IntersectionObserver"in window||(n.cancel(),document.removeEventListener("scroll",n))}})),r}return t(s,[{key:"componentDidMount",value:function(){this.infinityScrolling(document.querySelector(".scrollLoadingBar"),(function(e){e.props.getMoreData()}))}},{key:"componentWillUnmount",value:function(){this.infinityScrolling.closeMonitor&&this.infinityScrolling.closeMonitor()}},{key:"render",value:function(){return c.jsx("div",{className:"scrollLoadingBar",style:{opacity:0,width:"1px",height:"1px",zIndex:-1}})}}]),s}(require("react").Component);module.exports=s;