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

Adding "when to stop" functionality. #6

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
13 changes: 13 additions & 0 deletions js/flipcounter.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,17 @@ var flipCounter = function(d, options){
return this;
};

/**
* Sets the stop of the counter.
*
* @param {int} n
*
*/
this.setStop = function(n){
counter.stop = _isNumber(n) ? n : defaults.stop;
return this;
};

/**
* Increments counter by one animation based on set 'inc' value.
*/
Expand Down Expand Up @@ -165,6 +176,8 @@ var flipCounter = function(d, options){
_digitCheck(x, y);
// Do first animation
if (counter.auto === true) nextCount = setTimeout(_doCount, counter.pace);
// Stop counter
if (counter.value === counter.stop) _clearNext();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

=== forces you to have an exact value to stop the counter.
I suggest if (counter.value >= counter.stop) _clearNext(); to stop the counter.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Valid point

}

function _digitCheck(x, y){
Expand Down