var condition = ko.observable(true); //condition to keep the timer running var viewModel = { timer: new koTimer(180, { notifyTimeMarks: [60, 120], callback: function () { $('#timer').html('<span class="fin">Time is up!</span>'); }, keepGoing: condition //when the condition is false, the timer will stop }), stop: function () { condition(false); //set condition to false } }; //bind to TimeIsUp event $(document).on(viewModel.timer.Events.TimeIsUp, function () { //this event is fired when the timer reaches zero console.log('Time is up!'); }); //bind to TimeMarkHit event $(document).on(viewModel.timer.Events.TimeMarkHit, function (ev) { //this event is fired every time a time mark is hit console.log('Time elapsed: ' + ev.timeElapsed + ' seconds'); if (ev.timeElapsed === 120) { //during last minute, animate size of counter //animation time in milliseconds = 1 minute $('#timer').find('span').animate({ fontSize: '80px' }, 60 * 1000); } }); //apply ko bindings ko.applyBindings(viewModel, $('.main')[0]);
<div class="main"> <h1>THIS IS A TIMER</h1> <div id="timer"> <span data-bind="text: timer.TimeLeftStr"></span> </div> <button data-bind="click: stop">Stop Timer</button> </div>