zoukankan      html  css  js  c++  java
  • 滚动轴滚动方向判断

    开始时的判断代码,通过在滚动函数当中再监听一个滚动函数,然后判断前后的差值来判断是向上滚动还是向下滚动

    changeIsDownStatus = () => {
        const listView = this.listView;
        const beforeScrollTop = listView.scrollTop;
        this.listView.addEventListener('scroll', () => {
          const afterScrollTop = listView.scrollTop;
          this.isDown = afterScrollTop > beforeScrollTop;
        });
      };

    优化后的方法,通过当前的值减去缓存的值,然后再把缓存的值更新为当前的这种方式来判断滚动的方向,这种方式的性能比上面那种更好,同时代码更加的简洁

    changeIsDownStatus = () => {
        const listView = this.listView;
        this.isDown = listView.scrollTop > this.beforeScrollTop;
        this.beforeScrollTop = listView.scrollTop;
        return this.isDown;
      };
  • 相关阅读:
    近期总结
    input
    mysql语句
    同步与异步
    localStorage的增删查改封装函数
    最基本的前后台传值
    前段存储的调用函数
    js 控制弹出窗口的大小
    拖拽
    jQuery镇张缩小动画
  • 原文地址:https://www.cnblogs.com/kugeliu/p/9205299.html
Copyright © 2011-2022 走看看