如何使用 vanilla js 在 Cordova/Capacitor/Conic 中以编程方式滚动

How to scroll programmatically in Cordova / Capacitor / Conic using vanilla js

我确实进行了很多搜索,但没有找到可接受的答复,所以这是问题以及我的解决方案,供其他正在为此苦苦挣扎的人。

问题:我们不能再使用 window.scrollTo(),以编程方式滚动它因性能问题而被禁用。

解决方案:所以我们需要做这样的事情:

顶部 div 应该放在顶层(并且应该只有一个顶部 div)在 html 和以下 css:

.div-scrollable {
    overflow-y: auto;
    position: relative;
    height: 100vh;
    top: 0;
}

像这样我们可以使用顶部 div 来滚动,这里的命令可以很好地做到这一点:

document.getElementsByClassName('div-scrollable')[0].scrollTo({ top: y, behavior: 'smooth' })

干杯!