Countdown timer with reset function using jquery and downCount

生来就可爱ヽ(ⅴ<●) 提交于 2020-01-17 05:10:28

问题


I am using the countdown timer from http://www.jqueryscript.net/time-clock/Extremely-Lightweight-jQuery-Countdown-Timer-Plugin-downCount.html

I would like to add a button that resets the timer. There is no built in functionality, so I wrote my own function to do it. I am very new to javascript and can't get the clock to countdown (works on my site, just not in jsfiddle for some reason) or actually reset. I built a JSFiddle here:

https://jsfiddle.net/9dzu7g6a/

reset function:

function reset(){
    var date = new Date();
    var day = date.getDate();
    var month = date.getMonth()+1;
    var year = date.getFullYear();
    var hour = date.getHours();
    var minutes = date.getMinutes();
    var seconds = date.getSeconds();

    var dateString = day + '/' + month + '/' + year + ' ' + hour + ':' + minutes + ':' + seconds;

    $('.countdown').downCount({
      date: dateString,
      offset: +.5
        });
    };

回答1:


You will need to edit the library your using to do this and add the reset function to that as currently it provides no way to stop a timer ones it has started.

This link will help you get started.

https://developer.mozilla.org/en-US/docs/Web/API/WindowTimers/clearInterval



来源:https://stackoverflow.com/questions/34707958/countdown-timer-with-reset-function-using-jquery-and-downcount

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!