Skip to content

alexanderGugel/raf-core

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Build Status

raf-core

Request Animation Frame as a beating heart.

Idea

Using requestAnimationFrame in a similar way as setTimeout is counterintuitive and cumbersome. This package introduces a new way of performing certain actions on every repaint by wiring up an EventEmitter as a single source of truth for window repaints.

Installation

  • Node.js, browserify npm install raf-core --save (yes, it even works on servers)
  • Require.js require(["raf-core"], ...

Example

var rafCore = require('raf-core');

// Executes a function on every window repaint
rafCore.on('beat', function () {
    console.log('Repaint');
});

Since rafCore is an instance of Node's EventEmitter, you can exploit all its features.

var rafCore = require('raf-core');

var onBeat = function () {
    console.log('Repaint');
};

rafCore.on('beat', onBeat);

// Removes the onBeat event listener after 5 seconds
setTimeout(function () {
    rafCore.removeEventListener('beat', onBeat);
}, 5000);

About

Request Animation Frame as a beating heart.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published