You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+21-6Lines changed: 21 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,17 +2,21 @@
2
2
3
3
This is a hook to control your scrollbar in react component!
4
4
5
-
**Live demo is <atarget="_blank"href="https://codesandbox.io/s/react-smooth-scroll-hook-vhudw?file=/src/App.js" >Here</a>.**
6
-
7
5
Basically; `useSmoothScroll` hook checks the `HTMLElement`'s API `scrollTo`, otherwise, use `requestAnimationFrame` to finish smooth scroll behaviour!
8
6
9
7
If you want to control the `speed` of scroll behaviour, it defaults to use `requestAnimationFrame` mode.
10
8
9
+
**Examples are <atarget="_blank"href="https://ron0115.best/react-smooth-scroll-hook/?path=/docs/hooks-usesmoothscroll--direction-x#basic" >Here</a>.**(Storybook)
10
+
11
+
**Live demo is <atarget="_blank"href="https://codesandbox.io/s/react-smooth-scroll-hook-vhudw?file=/src/App.js" >Here</a>.**(Codesandbox)
12
+
11
13
## Feature
12
14
13
-
- You don't need to warn about compatibility, it use rAF api on low version browsers.
14
-
- Provide `speed` on your demand, otherwise it would use the native API `element.scrollTo`.
15
-
- Provide `direction` option ,you can set `x` for vertical, `y` for horizontal.
15
+
- 🚀 You don't need to warn about compatibility, it use `requsetAnimationFrame` api to finish smooth scroll behaviour.
16
+
17
+
- 👉 Provide `direction` option ,you can set `x` for vertical, `y` for horizontal.
18
+
19
+
- 💧 No Third Party dependencies, light and pure.
16
20
17
21
## Installation
18
22
@@ -65,7 +69,18 @@ export const Demo = () => {
65
69
66
70
### Returns of Hook
67
71
68
-
-`scrollTo(string | number)`
72
+
-**scrollTo**`(string|number) => void`
69
73
70
74
- Pass `number`: the distance to scroll, e.g. `scrollTo(400)`
71
75
- Pass `string`: the element seletor you want to scrollTo, passing to `document.querySelector`, e.g. `scrollTo('#your-dom-id')`
76
+
77
+
-**reachTop**`boolean`: Whether it is reach top of scrollContainer
78
+
79
+
-**reachBottom**`boolean`: Whether it is reach bottom of scrollContainer
80
+
81
+
-**scrollToPage**`(number) => void`: Pass page(`number`), which scroll to a distance as multiples of container size(`offsetWidth`/`offsetHeight`)
82
+
.e.g `scrollToPage(1)`,`scrollToPage(-1)`
83
+
84
+
-**refreshState**`() => void`: Manually refresh the state of `reachTop` and `reachBottom`, just an API as you need, and possibly useful in some situation.
85
+
86
+
-**refreshSize**`() => void`: Manually refresh the size of ref container, just an API as you need, and possibly useful in some situation.
0 commit comments