0

I am having trouble chaining my a javascript function off of the TimeCircle jQuery plugin. To summarize, this plugin creates a timer, and I want to call a function when the timer reaches 0. In the documentation they provided a built in function end() that is called automatically when the timer reaches 0. The documentation only shows me how to chain a jQuery function:

$(".example").TimeCircles().end().fadeOut(); 

This is what the documentation says: end() To allow you to chain TimeCircles to other jQuery functions, you can use the end() function. The end function returns the jQuery object and allows you to trigger jQuery function as desired.

After the TimeCircle's countdown ends, I want to accomplish something like this:

$(".example").TimeCircles().end(function() { console.log("timer ended") });

However, the function is never called when it ends. Does anyone know how I could chain my own javascript function?

Here is the link to the plugin's documentation - http://git.wimbarelds.nl/TimeCircles/readme.php

1 Answer 1

1

The end() function looks like it gets called a single time upon creation of the TimeCircles. It looks like the way to do what you want is by using the addListener function like this:

    $(".example.stopwatch").TimeCircles().start().addListener(function (unit, value, total) { if (total === 0) {console.log('timer ended');}});

Here is a JS fiddle showing what you want https://jsfiddle.net/etzouox4/2/

Sign up to request clarification or add additional context in comments.

2 Comments

awesome! my question now is if I had a button that passes in an integer into the stop watch everytime it is pressed, how can I get the stop watch to reset the value each time. For example, the first time the TimeCircle is created I pass in 10 seconds. After 10 seconds ends and the alert message displays, I want to pass in 20 seconds. Currently, when I pass in 20 seconds, it still counts down from 10 seconds. I've tried using rebuild() and destroy() but none seem to work
Did this solve your problem? If so, can you please select this as the correct answer?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.