vue3 div自动滚动
<div ref="divRef"></div>
const timer = ref()
const divRef = ref()
// 自动滚动
function autoScroll() {
if (timer.value) window.clearInterval(timer.value)
// 设置定时器进行滚动
timer.value = setInterval(() => {
const container = unref(divRef)
container.scrollTop += 1
if (container.scrollHeight - container.clientHeight - container.scrollTop <= 10) {
container.scrollTop = 0
}
}, 100) // 滚动频率,单位为毫秒
}