vue 中判断向上滚动还是向下滚动
 <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')
            }
        },
}

 

posted on 2019-06-23 15:54  悬弟  阅读(5859)  评论(0编辑  收藏  举报