Search code examples
javascriptjquerytimercountdown

jQuery 360 countdown - Button to add seconds WHILE timer is runnig


I need a button that can add seconds while the timer is running. I got the timer from: https://github.com/johnschult/jquery.countdown360. This is the code that I have to put in my HTML.

  $("#countdown").countdown360({
         radius      : 120,
         seconds     : 30,
         fontColor   : '#FFFFFF',
         autostart   : false,
         onComplete  : function () { console.log('done') }
       }).start();

I tried to make the button myself but no succes.

document.getElementById('add').onclick = function(){
        // location.reload();
        $("#countdown").countdown360({seconds += 20}).start()
        }

<button id="add">Add</button>

Can someone help me out? Thanks!


Solution

  • The seconds are stored in clock.settings.seconds.

    var clock = $("#countdown").countdown360({
        radius: 60,
        seconds: 30,
        fontColor: '#FFFFFF',
        autostart: false,
        onComplete: function () {
            console.log('done')
        }
    })
    clock.start();
    
    $("#countdown").on("click", function() {
        clock.settings.seconds += 20;
    });
    

    demo (countdown360.js loaded in firefox but not in chrome)