You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
直接修改源码替换(Direct modification of source code replacement)
适合有洁癖的人,不愿使用小众包
It is suitable for people who are obsessed with cleanliness and do not want to use crowdsourcing
directive.js
constctx="@@InfiniteScroll";varthrottle=function(fn,delay){varnow,lastExec,timer,context,args;//eslint-disable-linevarexecute=function(){fn.apply(context,args);lastExec=now;};returnfunction(){context=this;args=arguments;now=Date.now();if(timer){clearTimeout(timer);timer=null;}if(lastExec){vardiff=delay-(now-lastExec);if(diff<0){execute();}else{timer=setTimeout(()=>{execute();},diff);}}else{execute();}};};vargetScrollTop=function(element){if(element===window){returnMath.max(window.pageYOffset||0,document.documentElement.scrollTop);}returnelement.scrollTop;};vargetComputedStyle=document.defaultView.getComputedStyle;vargetScrollEventTarget=function(element){varcurrentNode=element;// bugfix, see http://w3help.org/zh-cn/causes/SD9013 and http://stackoverflow.com/questions/17016740/onscroll-function-is-not-working-for-chromewhile(currentNode&¤tNode.tagName!=="HTML"&¤tNode.tagName!=="BODY"&¤tNode.nodeType===1){varoverflowY=getComputedStyle(currentNode).overflowY;if(overflowY==="scroll"||overflowY==="auto"){returncurrentNode;}currentNode=currentNode.parentNode;}returnwindow;};vargetVisibleHeight=function(element){if(element===window){returndocument.documentElement.clientHeight;}returnelement.clientHeight;};vargetElementTop=function(element){if(element===window){returngetScrollTop(window);}returnelement.getBoundingClientRect().top+getScrollTop(window);};varisAttached=function(element){varcurrentNode=element.parentNode;while(currentNode){if(currentNode.tagName==="HTML"){returntrue;}if(currentNode.nodeType===11){returnfalse;}currentNode=currentNode.parentNode;}returnfalse;};vardoBind=function(){if(this.binded)return;// eslint-disable-linethis.binded=true;vardirective=myInstance;varelement=directive.el;varthrottleDelayExpr=element.getAttribute("infinite-scroll-throttle-delay");varthrottleDelay=200;if(throttleDelayExpr){throttleDelay=Number(directive.vm[throttleDelayExpr]||throttleDelayExpr);if(isNaN(throttleDelay)||throttleDelay<0){throttleDelay=200;}}directive.throttleDelay=throttleDelay;directive.scrollEventTarget=getScrollEventTarget(element);directive.scrollListener=throttle(doCheck.bind(directive),directive.throttleDelay);directive.scrollEventTarget.addEventListener("scroll",directive.scrollListener);vardisabledExpr=element.getAttribute("infinite-scroll-disabled");vardisabled=false;if(disabledExpr){this.vm.$watch(disabledExpr,function(value){directive.disabled=value;if(!value&&directive.immediateCheck){setTimeout(()=>{doCheck.call(directive);});}});disabled=Boolean(directive.vm[disabledExpr]);}directive.disabled=disabled;vardistanceExpr=element.getAttribute("infinite-scroll-distance");vardistance=0;if(distanceExpr){distance=Number(directive.vm[distanceExpr]||distanceExpr);if(isNaN(distance)){distance=0;}}directive.distance=distance;varimmediateCheckExpr=element.getAttribute("infinite-scroll-immediate-check");varimmediateCheck=true;if(immediateCheckExpr){immediateCheck=Boolean(directive.vm[immediateCheckExpr]);}directive.immediateCheck=immediateCheck;if(immediateCheck){setTimeout(()=>{doCheck.call(directive);});}vareventName=element.getAttribute("infinite-scroll-listen-for-event");if(eventName){directive.vm.$on(eventName,function(){setTimeout(()=>{doCheck.call(directive);});});}};vardoCheck=function(force){varscrollEventTarget=myInstance.scrollEventTarget;varelement=myInstance.el;vardistance=myInstance.distance;if(force!==true&&myInstance.disabled)return;//eslint-disable-linevarviewportScrollTop=getScrollTop(scrollEventTarget);varviewportBottom=viewportScrollTop+getVisibleHeight(scrollEventTarget);varshouldTrigger=false;if(scrollEventTarget===element){shouldTrigger=scrollEventTarget.scrollHeight-viewportBottom<=distance;}else{varelementBottom=getElementTop(element)-getElementTop(scrollEventTarget)+element.offsetHeight+viewportScrollTop;shouldTrigger=viewportBottom+distance>=elementBottom;}if(shouldTrigger&&myInstance.expression){this.expression();}};varmyInstance=null;varmyDirective={mounted(el,binding,vnode){el[ctx]={
el,vm: binding.instance,expression: binding.value,};myInstance=el[ctx];varargs=arguments;el[ctx].vm.$nextTick(function(){if(isAttached(el)){doBind.call(el[ctx],args);}el[ctx].bindTryCount=0;vartryBind=function(){if(el[ctx].bindTryCount>10)return;//eslint-disable-lineel[ctx].bindTryCount++;if(isAttached(el)){doBind.call(el[ctx],args);}else{setTimeout(tryBind,50);}};tryBind();});}};exportdefaultmyDirective;
The text was updated successfully, but these errors were encountered:
使用我修改后的包(Use my modified package)
适合懒人
For lazy people
主要是生命周期vue2和vue3不通导致不兼容,还有一些其他细微变化
The main reason is that the life cycle vue2 and vue3 are incompatible, and there are some other minor changes.
我把改动后的项目,也上传到了npm上,方便大家直接使用
I also uploaded the changed project to npm, which is convenient for everyone to use directly.
也进行了开源,直接安装vue3-infinite-scroll-good ,用法和vue-infinite-scroll一模一样
As like as two peas, vue3-infinite-scroll-good is installed directly, and the usage is exactly the same as vue-infinite-scroll.
直接修改源码替换(Direct modification of source code replacement)
适合有洁癖的人,不愿使用小众包
It is suitable for people who are obsessed with cleanliness and do not want to use crowdsourcing
directive.js
The text was updated successfully, but these errors were encountered: