0.3.0 • Published 7 years ago
@janmarkuslanger/counterjs v0.3.0
⌚️ Counter.js
A small javascript counter
Install
npm i @janmarkuslanger/counterjs --save
Setup
const myCounter = new Counter({
start: 0; // defines the start index
end: Number.POSITIVE_INFINITY; // defines the end point
step: 1; // defines the size of a step
duration: 1000; // defines the duration between the steps in ms
});
// Start counting
myCounter.init();
// get Current index
myCounter.getCurrent();
// get the start
myCounter.getStart(); // 0
// get the end
myCounter.getEnd(); // Number.POSITIVE_INFINITY
Methods
- onInit(currentCount, counterobject);
- onAim(currentCount, counterobject);
- onStep(currentCount, counterobject);
- onStop(currentCount, counterobject);
Examples
Count from 0 to ∞
const myCounter = new Counter({
start: 0,
end: Number.POSITIVE_INFINITY
});
Count from 10 to -∞
const myCounter = new Counter({
start: 10,
end: Number.NEGATIVE_INFINITY
});
Count from 10 to 20 calling a function when the counter is by 20
const myCounter = new Counter({
start: 10,
end: 20,
onAim: function(index, component) {
console.log(index);
console.log(component);
}
});
Count from 10 to 20 calling a function every step
const myCounter = new Counter({
start: 10,
end: 20,
onStep: function(index, component) {
console.log(index);
}
});