javascript countdown timer pause resume -
First of all, there is no break in my countdown timer and the function resumes and the timer runs just fine. Now I added this feature, no problem has stopped, but there is a problem in resuming the time. Time does not just show from that place, from where it was and countdown from there. How do I change my code?
$ ('#pause'). Click (function () {// get current minute and second / var text = $ ('# countdown') .html (); var min_sec = text.split (":"); pause_minutes = min_sec [0] ; Pause_seconds = min_sec [1]; // Close timer / clear timeout (stop_start); // Hide pause button, Show Play button // $ ('# pause') Hide (); $ ('# cont' ). Show ();}); // click on the release button // $ ('# cont'). Click (function () {$ ('# cont'). Hide (); $ ('# pause'). Show (); // Pause_minutes near and pause_seconds // resume_time (pause_minutes, pause_seconds);}); Function resume_time (pause_minutes, pause_seconds) {// example: 1, 30 var start_time = new date (); end_time.setMinutes (start_time.getMinutes (+ + pause_minutes); end_time.setSeconds (start_time.getSeconds () + pause_seconds); update_timer (); } Function update_timer () {var current_time = new date (); Var remaining_time = new date (); Remaining_time .Setetime (and_time.gate time) - current_time.gate time ()); Var minutes = remaining_time.getwind (); Var seconds = remaining_time.getscand (); If (seconds and lieutenant; 10) {secs = '0' + seconds.Tratring (); } $ ("# Countdown"). Text (minutes + ":" + seconds); // If you call every other // if (minutes == '0' and seconds == '00') {$ ('. Big_words'). Html ('sorry, bar above'); $ ('.overlay') show ().; SetTimeout (function () {location.reload ();}, 2000); Go out; } Stop_start = setTimeout (update_timer, 1000); }
I've written a short timer for you to join it; -)
And here is an example of a work:
var countdown = (function ($) {// length MS version timeout = 10000; // interval MSW timegap = 1000; var current time = (new date ()) .gettime (); var endtime = (new date ()) .getTime () + timeout; var gitimeter = $ ('# countdown'); var geopause = $ ( '#pause') Var GuiResume = $ ('# resume'). Hide (); var is running = true; var UpdateTimer = function (// run for timeout if (current time + timegap & lt; timeout) } {setTimeout (Updated Timer, Timegap);} // Countdown if Running (On) {Up Time of time + = timegap; if (current time> time = time) {GUITIMER CSS ('color', 'red');}} // updated GUI time = new date (); time.settime (end time-ontime ); Var min = time.get minutes (); veer seconds = time.get esounds (); guitimer.HTML ((min and lt; 10? '0': '') + minute + ':' + (seconds and Lefthinum; 10? '0': '') + sec);}; pause = action () {running = false; guiPause.hide (); guiResume.show ();}; var resume = function () {running = True; GuiPause.show (); GuiResume.hide (); }; Var start = function (timeout) {timeout = timeout; Current time = (new date ()) .gettime (); Endtime = (new date ()). Get Time () + Timeout; UpdateTimer (); }; Return {Stop: Stop, Restart: Restart, Start, Start: Start}; }) (JQuery); JQuery ('# pausing') ('click', CountDown.Pause). JQuery ('# resume') ('Click', CountDown.Resume). // ms countdown.start (120000);
Comments
Post a Comment