https://github.com/o2web/raf
requestAnimationFrame handler
https://github.com/o2web/raf
Last synced: 8 months ago
JSON representation
requestAnimationFrame handler
- Host: GitHub
- URL: https://github.com/o2web/raf
- Owner: o2web
- License: gpl-2.0
- Created: 2015-02-03T17:00:02.000Z (over 11 years ago)
- Default Branch: master
- Last Pushed: 2019-04-26T15:17:47.000Z (about 7 years ago)
- Last Synced: 2025-09-24T21:28:00.422Z (9 months ago)
- Language: JavaScript
- Homepage:
- Size: 583 KB
- Stars: 1
- Watchers: 14
- Forks: 4
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# raf.js
RequestAnimationFrame handler is made to increase performance of events fired by the window element
Supports AMD / CommonJS loaders
## Data
All raf.js data you might need is stored in a global variable named raf.
window.raf = {
request: 0 // current raf request
events: [], // list of events hooked to raf
eventsCount: 0, // current count of events
pointer: {}, // pointer position, updated if pointermove event is hooked
scroll: {}, // scroll position, updated if scroll event is hooked
on: function(), // start raf loop
off: function(), // stop raf loop, useful for debugging
loop: function(), // request another frame
updateDataSources(), // update dom/prefix combos used for resize detections
detects: {}, // Events available for detection
inits: {}, // Available init callbacks when first occurence of event is hooked
kills: {}, // Available kill callbacks when last occurence of event is unhooked
win: {}, // Data used for window calculations
doc: {}, // Data used for window calculations
}
## Available events
- scroll
- pointermove
- windowresize
- documentresize
- afterwindowresize
- afterdocumentresize
- nextframe
- eachframe
## Hooking your callback onto an event
window.raf.on('scroll', myScrollCallback);
window.raf.on('documentresize', myResizeCallback);
window.raf.on('afterdocumentresize', myHeavyResizeCallback);
## Removing your callback from an event
window.raf.off('scroll', myCallback);