Mouse wheel events in Reactjs

后端 未结 2 1658
感动是毒
感动是毒 2021-02-19 02:17

How do you go about getting mouse wheel events in reactjs?

I have tried onWheel

  render: function() {
    return 
2条回答
  •  别那么骄傲
    2021-02-19 02:51

    First, your div is 0 height, so you don't scroll on it. You don't have to bind this as it is a class (and not an es6 react component). Just do a call to the function with the event as parameter on onWheel event:

    https://jsfiddle.net/812jnppf/9/

    render: function() {
    
       return 
    this.wheel(e)} > < /div>; },

    Of course, you have to clean code to style your div with a var or in css.

    EDIT : I set it onWheel and not on onScroll (witch doesn't exist I guess ? confirm it if you know). I saw a SO post about adding scroll event to your component easilly : https://stackoverflow.com/a/29726000/4099279

提交回复
热议问题