vue 中判断向上滚动还是向下滚动
转载于 https://www.cnblogs.com/xianxiaoan/p/11073079.html
<script> export default { data(){ return{ i = 0 } }, mounted () { window.addEventListener('scroll', this.handleScroll, true); // 监听(绑定)滚轮 滚动事件 }, methods:{ handleScroll(){ // 页面滚动距顶部距离 var scrollTop = window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop var scroll = scrollTop - this.i; this.i = scrollTop; if(scroll<0){ console.log('up') }else{ console.log('down') } }, }