gpt4 book ai didi

javascript - 防止目标元素在某些情况下滚动到顶部

转载 作者:行者123 更新时间:2023-12-03 02:50:30 25 4
gpt4 key购买 nike

基本上,如果handleScroll函数内的if条件为真,我想禁用目标滚动到顶部。换句话说,如果条件为真。用户不应该再滚动到目标元素的顶部,也不能滚动到元素的底部。

如果可能的话,我也不希望溢出隐藏的解决方法。

target.addEventListener('scroll', e => this.handleScroll(e, sectionRect, offset, target));

handleScroll(event, sectionRect, offset, target) {
if ((sectionRect.top - offset) < target.scrollTop)
console.log('dont scroll', event);
},

最佳答案

我认为您不可能看到更多关于 scroll event here 的信息我还建议您查看这部分:

"Since scroll events can fire at a high rate, the event handler shouldn't execute computationally expensive operations such as DOM modifications. Instead, it is recommended to throttle the event using requestAnimationFrame, setTimeout or customEvent, as follows:"

这部分:

"In iOS UIWebViews, scroll events are not fired while scrolling is taking place; they are only fired after the scrolling has completed. See Bootstrap issue #16202. Safari and WKWebViews are not affected by this bug."

也许创建自定义卷轴可以是您的答案。

关于javascript - 防止目标元素在某些情况下滚动到顶部,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47887612/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com