vue3 + elementui table 设置自动滚动

定时器设置托条累加(鼠标覆盖时停止滚动)



utils文件夹下common.js

import { ref } from 'vue'

export default {
    scrollUp(tableRef) {
         const demo = tableRef.$refs.bodyWrapper.getElementsByClassName('el-scrollbar__wrap')[0]
         const tableScroll = ref(true)
         demo.addEventListener('mouseover', () => {
             tableScroll.value = false
         })
         demo.addEventListener('mouseout', () => {
             tableScroll.value = true
         })
         setInterval(() => {
             if(tableScroll.value) {
                 demo.scrollTop += 1
                 if(demo.clientHeight + demo.scrollTop === demo.scrollHeight) {
                     demo.scrollTop = 0
                 }
             }
         }, 100)
    }
}

你可能感兴趣的:(elementui,vue.js,前端)