且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在iFrame中使用Window.find()时如何禁用自动滚动

更新时间:2021-08-21 05:55:31

您可以在整个while循环完成之前禁用滚动,然后在其之后重新启用滚动.像这样:

You can disable scroll just before and re-enable it just after the whole while loop is done. Something like this:

window.addEventListener('scroll', noScroll);
// find logic
setTimeout(() => window.removeEventListener('scroll', noScroll), 500);

其中 noScroll 是禁用滚动的功能(类似于 window.scrollTo(0,0)).我发现在正在处理的脚本中添加 setTimeout 很有用,否则将触发最后一个事件.在您的情况下可能没用.

Where noScroll is your function that disables scrolling (something like window.scrollTo(0,0)). I've found useful adding the setTimeout in a script I was working on, otherwise the last event won'f fire. It may be useless in your case.