To use the animationFrames
function from the rxjs
library in TypeScript, you first need to import it from the library.
index.ts75 chars2 lines
Once you have imported the function, you can use it to create an Observable that emits the elapsed time between animation frames.
index.ts102 chars4 lines
The callback function in the subscribe method will be called on each animation frame, and will receive the elapsed time since the last frame as an argument.
You can also use RxJS operators like map
, filter
, scan
, etc. to transform the values emitted by the animationFrames
Observable.
index.ts288 chars9 lines
In this example, the map
operator is used to convert the elapsed time from milliseconds to seconds before logging it to the console.
gistlibby LogSnag