https://github.com/rwu823/raf-pause
🕐Set timeout in requestAnimationFrame
https://github.com/rwu823/raf-pause
pause raf requestanimationframe timeout timer
Last synced: 9 months ago
JSON representation
🕐Set timeout in requestAnimationFrame
- Host: GitHub
- URL: https://github.com/rwu823/raf-pause
- Owner: rwu823
- Created: 2018-07-27T12:30:37.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2023-12-15T20:30:36.000Z (over 2 years ago)
- Last Synced: 2025-01-07T17:46:57.948Z (over 1 year ago)
- Topics: pause, raf, requestanimationframe, timeout, timer
- Language: TypeScript
- Size: 125 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
## Installation
```sh
$ npm i raf-pause
```
or
```sh
$ yard add raf-pause
```
## API
### start()
Start the timer.
### clean()
Clean the timer.
## Recipes
```js
import rafPause from 'raf-pause'
const run = rafPause(() => {
// do something
}, 500)
run.start()
const runAndLoop = rafPause(() => {
// do something in loop
runAndLoop.start()
}, 500)
runAndLoop.start()
```
### In React
```js
import rafPause from 'raf-pause'
componentDidMount() {
this.countDown.start()
}
componentWillUnMount() {
this.countDown.clean()
}
countDown = rafPause(() => {
this.setState({
...
}, this.countDown)
}, 1000)
```
## Fallback
It'll fallback to `setTimeout` if browsers don't support `requestAnimationFrame`