https://github.com/dntzhang/raf-interval
setRafInterval and clearRafInterval with requestAnimationFrame - 40行代码实现的高性能动画定时器
https://github.com/dntzhang/raf-interval
clearinterval requestanimationframe setinterval tick ticker
Last synced: 2 months ago
JSON representation
setRafInterval and clearRafInterval with requestAnimationFrame - 40行代码实现的高性能动画定时器
- Host: GitHub
- URL: https://github.com/dntzhang/raf-interval
- Owner: dntzhang
- Created: 2014-11-12T07:21:03.000Z (almost 11 years ago)
- Default Branch: master
- Last Pushed: 2023-03-07T00:46:48.000Z (over 2 years ago)
- Last Synced: 2025-04-04T18:39:10.944Z (6 months ago)
- Topics: clearinterval, requestanimationframe, setinterval, tick, ticker
- Language: JavaScript
- Homepage:
- Size: 29.3 KB
- Stars: 81
- Watchers: 4
- Forks: 18
- Open Issues: 2
-
Metadata Files:
- Readme: readme.md
Awesome Lists containing this project
README
# raf-interval
setRafInterval and clearRafInterval with requestAnimationFrame.
# Usage
before raf-interval:
```js
var i = 0
var interval = setInterval(function() {
console.log(i++)
if (i > 6) {
clearInterval(interval)
}
},1000)
```after raf-interval:
```js
var i = 0
var rafInterval = setRafInterval(function() {
console.log(i++)
if (i > 6) {
clearRafInterval(rafInterval)
}
},1000)
```# Features
* Support setRafInterval and clearRafInterval like setInterval and clearInterval
* Automatically stops when the user switches to a different tab
* High performance animation with simple API
* Automatic stop the loop when it is not needed# Install
```
$ npm install raf-interval
```or get it by CDN:
* [https://unpkg.com/raf-interval@0.3.0/raf-interval.js](https://unpkg.com/raf-interval@0.3.0/raf-interval.js)
# License
This content is released under the [MIT](http://opensource.org/licenses/MIT) License.