1
1
# use-scroll-direction
2
+ [ ![ Latest Stable Version] ( https://img.shields.io/npm/v/use-scroll-direction.svg )] ( https://www.npmjs.com/package/use-scroll-direction )
3
+ [ ![ CI Status] ( https://github.com/AndrzejSala/use-scroll-direction/workflows/CI/badge.svg )] ( https://github.com/AndrzejSala/use-scroll-direction/actions )
4
+ [ ![ Gzipped size] ( https://img.shields.io/bundlephobia/min/use-scroll-direction?label=size )] ( https://www.npmjs.com/package/use-scroll-direction )
5
+ [ ![ License] ( https://img.shields.io/npm/l/use-scroll-direction.svg )] ( ./LICENSE )
6
+ [ ![ NPM total downloads] ( https://img.shields.io/npm/dt/use-scroll-direction.svg )] ( https://npmcharts.com/compare/use-scroll-direction?minimal=true )
7
+
2
8
A simple, performant and versatile hook for handling scroll in your react app.
3
9
4
10
## Installation
@@ -7,9 +13,9 @@ npm i use-scroll-direction
7
13
```
8
14
9
15
## Usage
10
- The hook returns the actual scroll direction which could be one of three states: ** 'NONE', 'DOWN', 'UP'** ;
16
+ The hook returns the actual scroll direction which could be one of three states: ** 'NONE'** , ** 'DOWN'** , ** 'UP'** ;
11
17
12
- ### On window
18
+ ### Use on window object
13
19
``` tsx
14
20
import {useScrollDirection } from " use-scroll-direction" ;
15
21
@@ -25,7 +31,7 @@ export const WindowExample = () => {
25
31
};
26
32
27
33
```
28
- ### On the element ref
34
+ ### Use on the specific element
29
35
``` tsx
30
36
import {useScrollDirection } from " use-scroll-direction" ;
31
37
@@ -34,11 +40,20 @@ export const ComponentRefExample = () => {
34
40
const scrollDirection = useScrollDirection ({ref: elementRef });
35
41
36
42
return (
43
+ // The content needs to overflow a container
37
44
<div ref = { elementRef } style = { {height: ' 100vh' , overflowY: ' scroll' }} >
38
45
<div >{ ... } </div >
39
46
</div >
40
47
)
41
48
};
42
49
```
43
50
44
- For more specific examples, check the demo app in ` ./example `
51
+ For more specific examples, check the demo app in ` ./example `
52
+
53
+ ## Available options
54
+
55
+ | Name | Type | Description |
56
+ | - | - | - |
57
+ | ` wait ` | ` ?number ` | Time in ms for throttling of scroll handler (default: 50)
58
+ | ` timeToReset ` | ` ?number ` | Time in ms after last scroll event to reset the state (default: 250)
59
+ | ` ref ` | ` ?string ` | When passed, the listener will be attached to element instead of window object
0 commit comments