Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Callback which is executed on each frame step #31

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ Of note to the developer, libjs.gif contains a class SuperGif, which can be used
* **max\_width** - Optional. Scale images over max\_width down to max_width. Helpful with mobile.
* **rubbable** - Optional. Make it rubbable.
* **on_end** - Optional. Add a callback for when the gif reaches the end of a single loop (one iteration). The first argument passed will be the gif HTMLElement.
* **on_framestep** - Optional. Add a callback which is executed on each framestep. The first argument passed will be the current frame index.
* **loop_delay** - Optional. The amount of time to pause (in ms) after each single loop (iteration).
* **progressbar_height** - Optional. The height of the progress bar.
* **progressbar_background_color** - Optional. The background color of the progress bar.
Expand Down
2 changes: 1 addition & 1 deletion example.html
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,4 @@ <h1>Example with rubbing and auto-play on</h1>

</body>

</html>
</html>
7 changes: 6 additions & 1 deletion libgif.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
auto_play Optional. Same as the rel:auto_play attribute above, this arg overrides the img tag info.
max_width Optional. Scale images over max_width down to max_width. Helpful with mobile.
on_end Optional. Add a callback for when the gif reaches the end of a single loop (one iteration). The first argument passed will be the gif HTMLElement.
on_framestep Optional. Add a callback which is executed on each framestep. The first argument passed will be the current frame index.
loop_delay Optional. The amount of time to pause (in ms) after each single loop (iteration).
draw_while_loading Optional. Determines whether the gif will be drawn to the canvas whilst it is loaded.
show_progress_bar Optional. Only applies when draw_while_loading is set to true.
Expand Down Expand Up @@ -460,6 +461,7 @@
options.auto_play = (!gif.getAttribute('rel:auto_play') || gif.getAttribute('rel:auto_play') == '1');

var onEndListener = (options.hasOwnProperty('on_end') ? options.on_end : null);
var onFrameStepListener = (options.hasOwnProperty('on_framestep') ? options.on_framestep : null);
var loopDelay = (options.hasOwnProperty('loop_delay') ? options.loop_delay : 0);
var overrideLoopMode = (options.hasOwnProperty('loop_mode') ? options.loop_mode : 'auto');
var drawWhileLoading = (options.hasOwnProperty('draw_while_loading') ? options.draw_while_loading : true);
Expand Down Expand Up @@ -706,7 +708,10 @@

var stepFrame = function (amount) { // XXX: Name is confusing.
i = i + amount;


if(onFrameStepListener !== null)
onFrameStepListener(i);

putFrame();
};

Expand Down