<template>
<div id="ceshi">
<ul>
<li v-for="item in 1000">{{item}}</li>
</ul>
</div>
</template>
<script>
import aa from '../App.vue'
export default {
data() {
return {
domObj: null,
list:[]
}
},
mounted() {
this.scrollFunction()
},
methods: {
scrollFunction() {
this.domObj = document.getElementById('ceshi') // 通过id获取要设置的div
if (this.domObj.attachEvent) { // IE
this.domObj.attachEvent('onmousewheel', this.mouseScroll)
} else if (this.domObj.addEventListener) {
this.domObj.addEventListener('DOMMouseScroll', this.mouseScroll, false)
}
this.domObj.onmousewheel = this.domObj.onmousewheel = this.mouseScroll
},
mouseScroll(event) { // google 浏览器下
let detail = event.wheelDelta || event.detail
let moveForwardStep = -1
let moveBackStep = 1
let step = 0
step = detail > 0 ? moveForwardStep * 100 : moveBackStep * 100
event.preventDefault() // 阻止浏览器默认事件
this.domObj.scrollLeft = this.domObj.scrollLeft + step
}
},
beforeDestroy() {
if (!this.domObj) return
if (this.domObj.attachEvent) {
this.domObj.detachEvent('onmousewheel', this.mouseScroll)
}
if (this.domObj.addEventListener) {
this.domObj.removeEventListener('DOMMouseScroll', this.mouseScroll, false)
}
}
}
</script>
<style>
#ceshi{
width: 500px;
background-color: antiquewhite;
margin: 100px auto;
overflow: hidden;
padding: 10px;
}
#ceshi ul{
list-style: none;
display: flex;
width: 20000px;
}
#ceshi ul li{
margin: 0 20px;
}
</style>
相关文章
- 11-05el-input的type=“number“ 隐藏上下标和禁止鼠标滚轮滚动
- 11-05WPF中关于自定义控件的滚动条鼠标停留在内容上鼠标滚轮滚动无效的问题
- 11-05vue监听鼠标滚轮滚动方向
- 11-05解决SourceGrid在某些系统上无法用鼠标滚轮滚动的问题
- 11-05JS网站广告实现侧边栏滚动至div顶部后固定、鼠标滚动下拉侧边栏DIV固定
- 11-05Qt中隐藏滚动条重新实现鼠标滚轮事件wheelEvent
- 11-05WPF中关于自定义控件的滚动条鼠标停留在内容上鼠标滚轮滚动无效的问题
- 11-05不难懂-----type=number 去掉加减按钮并禁止鼠标滚轮滚动
- 11-05div css 文字溢出可滑动,不出现滚动条
- 11-05appium自动化滑动鼠标滚动条的用法