判断页面滚动方向及触底

57 阅读1分钟
const handleScroll = useCallback(
    throttle((...args) => {
      const node = containerRef.current;

      if (node.scrollTop > scrollY.current) {
        console.log('dx----向下滚动');
        setShowFooter(false);
      } else {
        console.log('dx----向上滚动');
        setShowFooter(true);
      }
      if (node.scrollHeight - node.scrollTop === node.clientHeight) {
        console.log('dx---reachBottom', args);
        setShowFooter(true);
      }
      scrollY.current = node.scrollTop;
    }, 500),
    []
);