1. 程式人生 > 其它 >React 中實現滾輪觸發的橫向滾動

React 中實現滾輪觸發的橫向滾動

技術標籤:前端ReactJS

在要滾動的元件上新增 onWheel事件回撥函式yWheel

        <div ref={this.container} className={style.container} onWheel={this.yWheel}>
            {this.listDom()}
        </div>

定義yWheel

  yWheel(e) {
    e.currentTarget.scrollLeft += e.deltaY;
  }