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

2022-04-13 13:46:04 浏览数 (1)

代码语言:javascript复制
<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>

0 人点赞