遇到很奇怪的问题本来使用scrollTop方法在电脑上生效。在安卓手机上却没有生效。
scrolltop和scrollTo 在安卓上都无效。本地浏览器上没问题。
scrollTop参数详情
结果用安卓手机发现没有跳转。
只能使用scrollIntoView了。哎。看一下这个api有什么参数吧
scrollIntoView参数详情
behavior:smooth(平滑滚动),instant(瞬间滚动),默认值auto,实测效果等同于instant
document.getElementById(index).scrollIntoView({
behavior: "auto", block: "center", inline: "center"
});
给div加上id(index是for循环中的index,给了:id='index'),scrollIntoView会跳转到这个div的头部位置。
虽然不是很精准,但是好歹还能跳吧。。。