复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23methods: { handleScroll(e) { const scrollTop = e.target.scrollTop const scrollWrap = document.getElementById('scroll-wrap') const offsetTop = scrollWrap.offsetTop if (scrollTop > offsetTop) { // 滚动值大于偏移值 scrollWrap.style.position = 'fixed' // 鼠标滚动到一定距离实现定位 } else { scrollWrap.style.position = 'static' } } } mounted() { // 滚动监听事件 window.addEventListener('scroll', this.handleScroll, true) }, beforeDestroy() { // 离开该页面需要移除监听的事件 window.removeEventListener('scroll', this.scrollToTop, true) }
最后
以上就是无限自行车最近收集整理的关于vue 鼠标滚动事件处理定位问题的全部内容,更多相关vue内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复