// 获取表格滚动区域的dom
const scrollDom = tableRef.value.$refs.bodyWrapper.getElementsByClassName('el-scrollbar__wrap')[0];
timer = setInterval(() => {
if (status && props.listData.length > 0) {
// 设置每次滚动的像素
scrollDom.scrollTop = scrollDom.scrollTop + step.value;
console.log(scrollDom.scrollTop);
// 当滚动到底部时修改scrollTop回到顶部
if (scrollDom.scrollHeight - (scrollDom.clientHeight + scrollDom.scrollTop) < 1) {
scrollDom.scrollTop = 0;
}
}
}, 15);
如图:
scrollDom.scrollTop = 0;step.value = 1;
为什么相加后赋值结果是0.6666666865348816
已经排除精度丢失的原因,还能是因为什么呢
step的赋值逻辑没看到
scrollTop取的是dom元素垂直方向滚动距离,
0 + 1没有误差,那只可能是 + 1的时候scrollTop不是0
对scrollTop取值可以做个取整操作