Skip to content

setRafInterval and clearRafInterval with requestAnimationFrame - 40行代码实现的高性能动画定时器

Notifications You must be signed in to change notification settings

dntzhang/raf-interval

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

38 Commits
 
 
 
 
 
 
 
 

Repository files navigation

raf-interval

setRafInterval and clearRafInterval with requestAnimationFrame.

Usage

before raf-interval:

var i = 0
var interval = setInterval(function() {
    console.log(i++)
    if (i > 6) {
        clearInterval(interval)
    }
},1000)

after raf-interval:

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:

License

This content is released under the MIT License.

About

setRafInterval and clearRafInterval with requestAnimationFrame - 40行代码实现的高性能动画定时器

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published