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