An open API service indexing awesome lists of open source software.

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行代码实现的高性能动画定时器

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.