EN
React - onWheel example
1 points
In this article, we would like to show you onWheel
event in React.
In the example below, we create <div>
element with a scrollbar. As we scroll the list inside the div with a mouse wheel, onWheel
triggers handleOnWheel
method which displays that list is being scrolled.
Runnable example:
xxxxxxxxxx
1
// Note: Uncomment import lines while working with JSX Compiler.
2
// import React from 'react';
3
// import ReactDOM from 'react-dom';
4
5
const appStyle = {
6
width: '100px',
7
height: '100px',
8
overflow: 'scroll',
9
};
10
11
const handleOnWheel = () => {
12
console.log('onWheel: scrolling the list...');
13
};
14
15
const App = () => {
16
return (
17
<div style={{ height: '100px' }}>
18
<div style={appStyle} onWheel={handleOnWheel}>
19
<ul>
20
<li>List_item_1</li>
21
<li>List_item_2</li>
22
<li>List_item_3</li>
23
<li>List_item_4</li>
24
<li>List_item_5</li>
25
</ul>
26
</div>
27
</div>
28
);
29
};
30
31
32
const root = document.querySelector('#root');
33
ReactDOM.render(<App />, root );