Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9139549
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T09:24:08+00:00 2026-06-17T09:24:08+00:00

My problem is that timer doesn’t pause correctly. When I hit pause it looks

  • 0

My problem is that timer doesn’t pause correctly. When I hit pause it looks like it has stopped but actually it continues to cycle, and when I hit start it doesn’t continue from where I paused, but from the location it had reached.

<div class="stopwatch">
    <span>00:00:00,000</span><br />
    <div class="btn start">play</div>
    <div class="btn pause">pause</div>
    <div class="btn reset">reset</div>
</div>
$(function (){  
    var reload = 1000/60;  
    var timer = null;  
    var startTime = 0;  
    var btn = $('.stopwatch a');  
    var count = $('.stopwatch span');  
    var pause = false;

    $('.pause').click(function (){
        pause = true; 
    });
    $('.start').click(function (){
        pause = false; 
    });
    $('.reset').click(function (){
        return ( (count.text('00:00:00,000')) && (timer = 0) );
    });

    function zero(num, length) {  
        if ( typeof(length) == 'undefined' ) length = 2;  

        while ( num.toString().length < length ) {  
            num = '0' + num;  
        }  
        return num;  
    }  

    function zero_format(time){  
        return zero(time.getUTCHours()) + ':' + zero(time.getMinutes()) + ':' + zero(time.getSeconds()) + ',' + zero(time.getMilliseconds()); 
    }  

    $('.start').click( function (){  
        if ( !timer ){  
            startTime = new Date();  
            timer = setInterval( function (){  
                if ( pause ){
                    return;
                }

                var currentTime = new Date(new Date() - startTime);  
                count.text(zero_format(currentTime));  
            }, reload);
        }
        return false;
    });
});   
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T09:24:08+00:00Added an answer on June 17, 2026 at 9:24 am

    You have two handlers for $('.start').

    Try this: Live Demo

    $('.start').click(function (){  
        if ( !timer ){  
            startTime = new Date();  
            timer = setInterval( function (){  
                if ( pause ){
                    return;
                }
    
                var currentTime = new Date(new Date() - startTime);  
                count.text(zero_format(currentTime));  
            }, reload);
        } else {
            pause = false; 
        }
    
        return false;
    });
    

    And remove this:

    $('.start').click(function (){
        pause = false; 
    });
    

    Update 1

    If you need a stopwatch, not a lap timer, then here is the code: Live Demo

    var savedTime;
    var additional = 0;
    
    $('.pause').click(function (){
        savedTime = new Date(); 
        pause = true; 
    });
    
    $('.reset').click(function (){
        count.text('00:00:00,000');
        clearInterval(timer);
        timer = null;
        additional = 0;
    });
    
    $('.start').click( function (){  
        if ( !timer ){  
                  startTime = new Date();  
            timer = setInterval( function (){  
                if ( pause ){
                    return;
                }
    
                currentTime = new Date(new Date() - startTime - additional);  
                count.text(zero_format(currentTime));  
            }, reload);
    
            pause = false;
        }
    
        if(pause == true) {
            additional += new Date() - savedTime;
            pause = false; 
        }
    
       return false;
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My problem is that every time I do some operation with an URL like
I'm noticing a problem that has crept up a few times over the years,
I have a really silly problem that has cost me a load of time
I would like to restart my timer when I receive a KeepAlive, the problem
OK... Looks like WinForms and Threading in the same program is something that I
A recent question contains a problem that I many times used to think about
Right now the problem is that the first time when I click the image,
I have a problem that I'm working on for quite some time now. I
I have a simple problem that I've been stuck on for some time and
My problem is when dialog box is showing at that time may i click

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.