Allow you to control and switch an image source to play as a MovieClip.
npm install -S image-reader
var ImageReader = require('image-reader');
var reader;
// preload all your images, then
reader = new ImageReader([
'/media/img1.jpg',
'/media/img2.jpg',
'/media/img3.jpg',
'/media/img4.jpg',
'/media/img5.jpg'
]);
anim();
function anim() {
requestAnimationFrame(anim);
reader.update();
}
new ImageReader(images[, options]);
The image urls that are going to be switched. Preloading them will avoid flickering.
Start playing immediately when instanciated
The targeting image element. If not provided, one will be created and must be inserted, accessible through el
property.
FPS of the animation
Starting url, indexed from the array you pass at constructor.
Loop when it reaches to
value
Called when the animation complete. Does not work if repeat is set.
Called at each repeat
Called when the animation has played all repeat
How many time the animation should repeat
If true, the created image (if no one was provided) would be styled with width
and height
divided by 2
If true
, animation will be played in reverse side
Frame to stop the animation, indexed from the array you pass at constructor.
Update the current image src according to fps
. This method has to ba called by your own in a raf.
- force
Boolean
false
: Ifforce
is set totrue
, FPS will be ignore and current src will be updated
Start playing from last known position
Pause at current position
Stop playing and set current position to from
value
Switch playing side, optionaly forcing it
- side
Boolean
null
: Switch playing side. If side is set totrue
, normal side will be forced;false
will force reverse.
from
or to
can be omitted.
- from
Number
: Set starting frame and go to it - to
Number
: Set ending frame
- frame
Number
: Move cursor toframe
and start playing
- frame
Number
: Move cursor toframe
and stop playing
Stop playing and remove image element from the DOM
Return the targeting image element. If no el
was given to the constructor, you will have to add this to your page.
Return the current frame, index0 based
Return images array length
FPS of the animation
Loop when it reaches to
value
How many time the animation should repeat
Called when the animation complete. Does not work if repeat is set.
Called at each repeat
Called when the animation has played all repeat
If relies on performance.now()
. You could need a polyfill for IE9
perfnow
polyfill installation withnpm install -S perfnow
First you should install EditorConfig package in your code editor. Then,
cd .git/hooks
ln -s ../../hooks/pre-commit
npm install
Then 2 commands are available :
npm run watch
watch and build js filesnpm run build
clean, build and uglify js files