soma56
soma56

Reputation: 69

How to stop flip timer at a specific number

I'm playing with a counter that won't stop. I'd like it to stop at a specific number.

// Initialize a new counter
var myCounter = new flipCounter('flip-counter', {
    value: 0, 
    inc: 1, 
    pace: 6, 
    auto: true
});

I'm was thinking it would be something along the lines of the following:

if (flipCounter.value > 10) {
    myCounter.stop();
}

If someone could point me in the right direction it would be appreciated.

Upvotes: 1

Views: 148

Answers (1)

Gurpreet Singh
Gurpreet Singh

Reputation: 21233

Use incrementTo(num, time, pace)

From their docs:

incrementTo(num, time, pace) new Increments to a given number either by using the currently set pace and inc values, or by using a "smart" increment technique that determines optimal values for you. To use the simple technique, all you need to supply is the target number: myCounter.incrementTo(12345); This will increment to 12,345 using the current pace and inc values. To use the smart method, supply the time in seconds you want the increment process to last, and a desired pace: myCounter.incrementTo(12345, 10, 400); This will increment to 12,345 as well, but the increment process will take 10 seconds to complete. The counter will determine the optimal values to use. In the example I've set a desired pace of 400, which the counter will try and stay as close to as possible when finding the optimal values. This method is not chainable. num [int]: Number to increment to. time [int] (optional): Duration, in seconds, the increment process should take. When set, the counter will use a smart increment technique to optimize the animation. pace [int] (optional): Desired pace for animation when using the smart increment option. This number may increase as needed for optimal timing.

Upvotes: 1

Related Questions