element-plus el-scrollbar 滚轮横向滚动

<template>
	<el-scrollbar ref="refScrollbar" @wheel.prevent="handleScroll">
		<div class="ct-scrollbar">
		</div>
	</el-scrollbar>
</template>

<script>
export default {
  setup() {
    const refScrollbar = ref(null)
    return {
      refScrollbar,
      handleScroll: (e) => {
        const wheelDelta = e.wheelDelta || -e.deltaY * 40
        const scrollbar = refScrollbar.value
        // scrollbar.wrap$获取到包裹容器的element对象
        scrollbar.setScrollLeft(scrollbar.wrap$.scrollLeft + wheelDelta)
      }
    }
  }
}
</script>

<style scoped>
.ct-scrollbar {
  display: flex;
}
</style>

posted on 2022-04-11 22:37  路过君  阅读(504)  评论(0编辑  收藏  举报

导航