vue-infinite-scroll库在Modal和Drawer中无效问题解决

更新时间:2023-07-18 16:52:27 阅读: 评论:0

image.png
原因呢在上⾯的参考连接上已经有了(在这⾥我在贴出来⼀下)
1.弹窗启动时,未经过mounted⽣命周期,所以未绑定成功滚动事件
2.获得监听滚动函数的element时(get Scroll EventTarget),也就是滚动的容器时,未能拿到overflowY的值,是根据这个值去返回当前滚动容器的元素。否则拿不到返回window的值。
这个博主也给出了解决⽅案,就是修改滚动加载库源代码
这个博主修改后的:
请看到最后⾯,因为还有⼀个坑,没有完全解决,最后⾯的解决了遗留的问题
const ctx = '@@InfiniteScroll';
let throttle = function (fn, delay) {step up
let now, lastExec, timer, context, args; //eslint-disable-line
let execute = function () {
fn.apply(context, args);tomorrowwillbebetter
lastExec = now;
};
return function () {
context = this;
args = arguments;
now = w();
if (timer) {
clearTimeout(timer);cu
timer = null;
}
if (lastExec) {
let diff = delay - (now - lastExec);
if (diff < 0) {
execute();
} el {interest是什么意思
timer = tTimeout(() => {
execute();
}, diff);
}
} el {
execute();
}
}
};
滚动体
};
let getScrollTop = function (element) {
天人合一英文
if (element === window) {
return Math.max(window.pageYOfft || 0, document.documentElement.scrollTop);
}
你从哪里来 英文return element.scrollTop;
};
let getComputedStyle = ComputedStyle;
let getScrollEventTarget = function (element) {
let currentNode = element;
// bugfix, e w3help/zh-cn/caus/SD9013 /questions/17016740/onscroll-function-is-not-working-for-chrome  while (currentNode && currentNode.tagName !== 'HTML' && currentNode.tagName !== 'BODY' && deType === 1) {
let overflowY = getComputedStyle(currentNode).overflowY;
let overflowYStyle = currentNode.style.overflowY
if (overflowY === 'scroll' || overflowY === 'auto' || overflowYStyle === 'auto') {
return currentNode;
}
currentNode = currentNode.parentNode;
}
return currentNode;
};
let getVisibleHeight = function (element) {
if (element === window) {
return document.documentElement.clientHeight;
}
return element.clientHeight;
};
let getElementTop = function (element) {
if (element === window) {
return getScrollTop(window);
}
BoundingClientRect().top + getScrollTop(window);
};
let isAttached = function (element) {
let currentNode = element.parentNode;
while (currentNode) {
if (currentNode.tagName === 'HTML') {
在线翻译 汉译英return true;
}
if (deType === 11) {
return fal;
}
currentNode = currentNode.parentNode;
}
return fal;
};
let doBind = function () {
if (this.binded) return; // eslint-disable-line
this.binded = true;
let directive = this;
let element = directive.el;
find my iphonelet throttleDelayExpr = Attribute('infinite-scroll-throttle-delay');
let throttleDelay = 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);
this.vm.$on('hook:beforeDestroy', function () {
veEventListener('scroll', directive.scrollListener);
});
let disabledExpr = Attribute('infinite-scroll-disabled');
let disabled = fal;
console.log('disabledExpr', disabledExpr)
if (disabledExpr) {
this.vm.$watch(disabledExpr, function (value) {
directive.disabled = value;
if (!value && directive.immediateCheck) {
doCheck.call(directive);
}
});
disabled = Boolean(directive.vm[disabledExpr]);
}
directive.disabled = disabled;
let distanceExpr = Attribute('infinite-scroll-distance');
let distance = 0;
if (distanceExpr) {
distance = Number(directive.vm[distanceExpr] || distanceExpr);
if (isNaN(distance)) {
distance = 0;
}
}
directive.distance = distance;
let immediateCheckExpr = Attribute('infinite-scroll-immediate-check');
let immediateCheck = true;
if (immediateCheckExpr) {
immediateCheck = Boolean(directive.vm[immediateCheckExpr]);
}
directive.immediateCheck = immediateCheck;
if (immediateCheck) {
doCheck.call(directive);
}
let eventName = Attribute('infinite-scroll-listen-for-event');
if (eventName) {
directive.vm.$on(eventName, function () {
doCheck.call(directive);
});
}
};
const doCheck = function (force) {
let scrollEventTarget = this.scrollEventTarget;
let element = this.el;
let distance = this.distance;
if (force !== true && this.disabled) return; //eslint-disable-line
let viewportScrollTop = getScrollTop(scrollEventTarget);
let viewportBottom = viewportScrollTop + getVisibleHeight(scrollEventTarget);
let shouldTrigger = fal;
if (scrollEventTarget === element) {
小tip是什么意思shouldTrigger = scrollEventTarget.scrollHeight - viewportBottom <= distance;
} el {
let elementBottom = getElementTop(element) - getElementTop(scrollEventTarget) + element.offtHeight + viewportScrollTop;    shouldTrigger = viewportBottom + distance >= elementBottom;
}
if (shouldTrigger && pression) {

本文发布于:2023-07-18 16:52:27,感谢您对本站的认可!

本文链接:https://www.wtabcd.cn/fanwen/fan/78/1103435.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

标签:滚动   解决   容器   修改
相关文章
留言与评论(共有 0 条评论)
   
验证码:
推荐文章
排行榜
Copyright ©2019-2022 Comsenz Inc.Powered by © 专利检索| 网站地图