Class for run loop animation with RAF
npm
npm install request-animation-runner
yarn
yarn add request-animation-runner
import RequestAnimation from 'request-animation-runner';
const requestAnimation = new RequestAnimation();
requestAnimation.activate();
requestAnimation.run(() => {
// some logic
});
Disable call requests.
requestAnimation.deactivate();
requestAnimation.run(() => {
// some logic
}); // no effect
requestAnimation.activate();
requestAnimation.run(() => {
// some logic
}); // handler is called
Enable call requests.
requestAnimation.deactivate();
requestAnimation.run(() => {
// some logic
}); // no effect
requestAnimation.activate();
requestAnimation.run(() => {
// some logic
}); // handler is called
Resolve the animation loop calculates time elapsed since the last loop and only draws if your specified fps interval is achieved.
-
@param {function} animationFunc - Function for animation
-
@param {string} fps - Frames per Second
-
@returns {undefined}
requestAnimation.run(() => {
// some logic
});
Request single call.
-
@param {function} animationFunc - Function for animation
-
@returns {undefined}
requestAnimation.request(() => {
// some logic
});
Cancel current request.
- @returns {undefined}
requestAnimation.cancelRequest();
npm test
Krivega Dmitriy
- Website: https://krivega.com
- Github: @Krivega
Contributions, issues and feature requests are welcome!
Feel free to check issues page. You can also take a look at the contributing guide.
Copyright © 2020 Krivega Dmitriy.
This project is MIT licensed.