@z-utils/react
Version:
zzy 工具库/react
2 lines (1 loc) • 2.42 kB
JavaScript
import t from"@babel/runtime/helpers/classCallCheck";import e from"@babel/runtime/helpers/createClass";import n from"@babel/runtime/helpers/assertThisInitialized";import r from"@babel/runtime/helpers/inherits";import i from"@babel/runtime/helpers/possibleConstructorReturn";import o from"@babel/runtime/helpers/getPrototypeOf";import l from"@babel/runtime/helpers/defineProperty";import{jsx as c}from"react/jsx-runtime";import{Component as s}from"react";function u(t){var e=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(t){return!1}}();return function(){var n,r=o(t);if(e){var l=o(this).constructor;n=Reflect.construct(r,arguments,l)}else n=r.apply(this,arguments);return i(this,n)}}var a=function(i){r(a,s);var o=u(a);function a(e){var r;return t(this,a),r=o.call(this,e),l(n(r),"infinityScrolling",(function(t,e){var n,r=this;"IntersectionObserver"in window?new IntersectionObserver((function(t){r.props.getDataBol&&t[0].intersectionRatio&&e(r)})).observe(t):(n=function(t){var e,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(e),i||(i=l),l-i>r?(t.apply(o,c),i=l):e=setTimeout((function(){t.apply(o,c)}),n)}}((function(){if(!r.props.getDataBol)return;(function(t){var e=arguments.length>1&&void 0!==arguments[1]&&arguments[1],n=t.getBoundingClientRect(),r=n.top,i=n.left,o=n.bottom,l=n.right,c=window,s=c.innerHeight,u=c.innerWidth;return e?(r>0&&r<s||o>0&&o<s)&&(i>0&&i<u||l>0&&l<u):r>=0&&i>=0&&o<=s&&l<=u})(t,!0)&&e(r)}),100),document.addEventListener("scroll",n));this.infinityScrolling.closeMonitor=function(){"IntersectionObserver"in window||(n.cancel(),document.removeEventListener("scroll",n))}})),r}return e(a,[{key:"componentDidMount",value:function(){this.infinityScrolling(document.querySelector(".scrollLoadingBar"),(function(t){t.props.getMoreData()}))}},{key:"componentWillUnmount",value:function(){this.infinityScrolling.closeMonitor&&this.infinityScrolling.closeMonitor()}},{key:"render",value:function(){return c("div",{className:"scrollLoadingBar",style:{opacity:0,width:"1px",height:"1px",zIndex:-1}})}}]),a}();export{a as default};