问题描述
在IntersectionObserver
里面使用了xx.scrollTop = xx,经过测试在pc端完全正常,滚动条有滚动。但是在移动端(安卓),虽然有赋值成功,但是没有滚动。
环境
没有用到框架,为原生js
相关代码
this.selectedItem = new IntersectionObserver((entries) => {
entries.forEach((item) => {
if (item.isIntersecting) {
// 就是这行
this.yearScrollEl.scrollTop = 100
}
})
}, {
root: this.element.querySelector('.timePicker-wheel'),
threshold: [0.6]
})
this.element.querySelectorAll('li').forEach((item) => {
this.selectedItem.observe(item)
})
尝试过的方法(原理不懂)
加了一个定时器之后,在移动端就正常了:
setTimeout(() => {
this.yearScrollEl.scrollTop = 100
},300)
但是不知道原理,希望顺便能请教各位这一点