You can add onTouch event onTouch to your React components:
onTouchStart={touchStartEvent => this.handleTouchStart(touchStartEvent)} onTouchMove={touchMoveEvent => this.handleTouchMove(touchMoveEvent)} onTouchEnd={() => this.handleTouchEnd()}
You can also add event handlers for mouse events for cross-platform compatibility:
onMouseDown={mouseDownEvent => this.handleMouseDown(mouseDownEvent)} onMouseMove={mouseMoveEvent => this.handleMouseMove(mouseMoveEvent)} onMouseUp={() => this.handleMouseUp()} onMouseLeave={() => this.handleMouseLeave()}
You have the right idea to update the state property of the left state in the event handler, but if you want the scrolling function to look natural, you will need to track the position of the pointer (be it a mouse or touch) by updating left using the clientX event clientX .
To do this, you need to save the position of the first touch and set left equal to the change in the position of the touch. For added realism, you can also track the velocity of the click and continue animating the component after the completion of the touch.
Here's the quick n-dirty code I did to scroll to remove items from the list:
https://codepen.io/swingthing/pen/ZBGBJb/
source share