Skip to content
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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,4 @@ The following attributes can be set as numbers on the directive element.
- ```count-to``` the number to count to.
- ```value``` the number to start counting from.
- ```duration``` how long the count should take in seconds.

- ```precision``` number of decimals if count-to is a floating number.
2 changes: 1 addition & 1 deletion build/angular-count-to.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 7 additions & 6 deletions src/count-to.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,18 @@ var countTo = angular.module('countTo', [])
link: function (scope, element, attrs) {

var e = element[0];
var num, refreshInterval, duration, steps, step, countTo, value, increment;
var num, refreshInterval, duration, steps, step, countTo, value, increment, precision;

var calculate = function () {
refreshInterval = 30;
step = 0;
scope.timoutId = null;
countTo = parseInt(attrs.countTo) || 0;
scope.value = parseInt(attrs.value, 10) || 0;
precision = parseInt(attrs.precision) || 0;
countTo = parseFloat(attrs.countTo) || 0;
scope.value = parseFloat(attrs.value, 10) || 0;
duration = (parseFloat(attrs.duration) * 1000) || 0;

steps = Math.ceil(duration / refreshInterval);
steps = duration / refreshInterval;
increment = ((countTo - scope.value) / steps);
num = scope.value;
}
Expand All @@ -28,9 +29,9 @@ var countTo = angular.module('countTo', [])
if (step >= steps) {
$timeout.cancel(scope.timoutId);
num = countTo;
e.textContent = countTo;
e.textContent = countTo.toFixed(precision);
} else {
e.textContent = Math.round(num);
e.textContent = num.toFixed(precision);
tick();
}
}, refreshInterval);
Expand Down