• Stars
    star
    398
  • Rank 108,012 (Top 3 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created about 11 years ago
  • Updated over 6 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

An even better requestAnimationFrame

An even better requestAnimationFrame

  • fixed ios6 issues upgrading to the native implementation if it works (no agent sniffing)
  • like the native implementation it will group callbacks for better performance
  • like the native implementation it will degrade the frame rate depending on device performance
  • you can define your own frame rate specifically for every animation
  • highly optimized for performance
  • can be used as a shim, but has an own namespace per default
  • no performance degradation if using mutilple RAF calls in parallel (see examples/compare.html)

Usage

Get the api

If you are inside of a commonjs/amd module:

var AnimationFrame = require('animation-frame');

Otherwise its defined on window:

var AnimationFrame = window.AnimationFrame;

Activate the shim AnimationFrame.shim(options)

It will replace native implementation if it does exist but still will use it if possible. So you can use window.requestAnimationFrame and window.cancelAnimationFrame after this safely. Optionally you can pass the frame rate.

AnimationFrame.shim(options);

Set custom default frame rate

There are devices with different refresh rate than 60 out of there. You can define a custom value, for the shim implementation. Native implementation should do it for you. Do it before requesting frames, because after that the frame length is cached.

AnimationFrame.FRAME_RATE = 30;

Create instance new AnimationFrame(options)

Options can be an object or a number, number is the custom frame rate.

Options:

  • useNative use the native animation frame if possible, defaults to true
  • frameRate pass a custom frame rate
    // Using default frame rate
    var animationFrame = new AnimationFrame();

    // Using custom frame rate.
    var animationFrame = new AnimationFrame(20);

    // Avoid using native RAF:
    var animationFrame = new AnimationFrame({useNative: false});

Request a frame animationFrame.request(fn)

var frameId = animationFrame.request(function(time) {
    // Your animation here.
});

Cancel frame animationFrame.cancel(frameId)

var animationFrame = new AnimationFrame();
animationFrame.cancel(frameId);

Known problems

  • ios6-7 safari native animation frame animation can conflict with css animations, see #2

Credits

http://paulirish.com/2011/requestanimationframe-for-smart-animating

http://my.opera.com/emoller/blog/2011/12/20/requestanimationframe-for-smart-er-animating

https://gist.github.com/paulirish/1579671

https://gist.github.com/jonasfj/4438815

https://gist.github.com/KrofDrakula/5318048

License

MIT

More Repositories

1

jqtpl

[deprecated] A template engine for nodejs, browser and any other javascript environment.
JavaScript
212
star
2

emoticons

Parse text emoticons and replace them by graphics.
CSS
94
star
3

socket.io-mongo

[outdated] Mongodb store for socket.io.
JavaScript
86
star
4

react-nano-state

Fast state that can be shared across components outside of the React tree.
JavaScript
71
star
5

diff-renderer

Smart innerHTML for your views.
JavaScript
66
star
6

node-cjson

Comments enabled json loader (Commented JavaScript Object Notation)
JavaScript
61
star
7

simpleio

Simpleio - http based real time messaging backed by mongodb.
JavaScript
48
star
8

node-ams

[deprecated] asset management system for nodejs
JavaScript
39
star
9

feature-driven-architecture

Defining boundaries for a large application.
37
star
10

node-xpkg

Write x-package.json once and generate package.json, bower.json or whatever.json.
JavaScript
27
star
11

node-mongo-queue

Node.js job queue backed by MongoDB
CoffeeScript
25
star
12

remove-hover

Remove :hover rules from all stylesheets.
JavaScript
24
star
13

node-linter

[deprecared] Code quality tools collection in one nodejs module
Python
22
star
14

node-argsparser

A tiny command line arguments parser for node
JavaScript
18
star
15

cyclic

Cyclic is an api for creating single or bidirectional bindings between any kind of objects.
JavaScript
17
star
16

field-selection

jQuery plugin for getting selection or replace a text in input field and textarea
JavaScript
14
star
17

sharedjs

[deprecated - use underscore] Unified utilities lib for browser and nodejs to enable easier coding of shared code - deprecated.
JavaScript
13
star
18

express-struct

MVC project structure on top of express.
JavaScript
10
star
19

labs

my laboratory
JavaScript
10
star
20

xLazyLoader

[deprecated] jquery plugin for asynchron load of javascripts, css and images
JavaScript
10
star
21

node-busy

Detect if event loop is busy.
JavaScript
9
star
22

jquery-tiny-lightbox

Lightweight lightbox clone with different animations and slideshow.
JavaScript
9
star
23

micro-modules

Micro implementation of commonjs modules.
JavaScript
8
star
24

images-loader

Ultra performant dependences free images loader
JavaScript
7
star
25

hashchange

crossbrowser haschange event implementation using jquery's API for special events
JavaScript
7
star
26

node-connect-mongo-store

Session store for connect using mongodb
JavaScript
6
star
27

kiipost

[deprecated] its the first personal app that lets you collect the links you tweet and get updates only on what matters to you.
Java
6
star
28

loader

[dev] lazyload of js,css, images and templates, define your customized dependencies package, where you can not only describe all dependencies, but also define which files can be loaded asynchron and which synchron.
JavaScript
6
star
29

nodetime

Performance Profiler for Node.js
JavaScript
5
star
30

connect-debounce

Distributed debounced function execution like _.debounce on per session basis as connect middleware.
JavaScript
4
star
31

expose.js

expose.js is a module boilerplate for commonjs and browser
JavaScript
4
star
32

workshops

JavaScript
3
star
33

jquery-icrop

Simple image cropper
JavaScript
3
star
34

swipe-list

Infinite scroll replacement for weak mobile devices.
JavaScript
3
star
35

humanizedMessages

implementation of humanized messages introduced by ajaxian http://ajaxian.com/archives/humanized-messages-library
JavaScript
3
star
36

ipanel

Mobile slide panels.
JavaScript
2
star
37

react-jss

Use JSS from React components
JavaScript
2
star
38

flash

jquery plugin for embedding flash
JavaScript
2
star
39

exfont

jQuery plugin for morisawa fonts - http://www.morisawa.co.jp/english/ (it works only with morisawa server app)
JavaScript
2
star
40

fileUpload

[dev] jquery plugin for file upload using html5 ajax upload, flash or iframe for older browsers, that is seamlessly integrated in jquery ajax and events implementation.
JavaScript
2
star
41

Class

Classical inheritance emulation. It doesn't shares privileged properties between instances, so is more RAM intensive, but it gives you a lot of features known from classical OOP concept.
JavaScript
2
star
42

kof.github.io

Some of my identities.
HTML
1
star
43

oleg.id

My personal site
HTML
1
star
44

cssom-tests

JavaScript
1
star
45

table

jquery widget for rendering table using generic data and searching in it
JavaScript
1
star
46

jquery-actionController

actionController is a jquery plugin which goal is to simplify events management and to avoid tripple dependencies between html, css and javascript. It also improves events performance using delegation.
JavaScript
1
star
47

react-virtualized

React components for efficiently rendering large lists and tabular data
JavaScript
1
star