首页 > 解决方案 > 鼠标上下滚动时如何触发不同的功能

问题描述

我有两个功能 zoomin 和 zoomout。我想在向上滚动时触发 zoomin,在向下滚动时触发 zoomout。onwheel 不提供向上和向下功能

 onWheel={()=>this.zoomIn()}

标签: reactjsscrollmouseevent

解决方案


你可以从event.deltaY

onWheel={(e)=>this.zoomState(e)}
  zoomState(e) {
    switch (e.deltaY > 0) {
      case true:
        this.zoomIn();
        break;
      default:
        this.zoomOut();
    }
  }

推荐阅读