<div id="form1" class="whiteBox pagemain" ref="rightContent">
// 页面内容
</div>
new Vue({
el: '#form1',
data: {
i:0
},
mounted: function () {
this.$refs.rightContent.addEventListener('scroll', this.handleScroll, true);
// 监听(绑定)滚轮 滚动事件
},
methods: {
handleScroll: function () {
// 页面滚动距顶部距离
var scrollTop = this.$refs.rightContent.scrollTop;
var scroll = scrollTop - this.i;
this.i = scrollTop;
if (scroll < 0) {
console.log("up");
} else {
console.log("down");
}
},
})
使用vue判断页面滚动方向
最新推荐文章于 2025-01-12 09:49:05 发布