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 8762587
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T15:33:57+00:00 2026-06-13T15:33:57+00:00

I’m having a working countdown timer the only thing is i need to show

  • 0

I’m having a working countdown timer the only thing is i need to show it multiple times and I can’t seem to get it working for multiple counters.

The working code : http://jsfiddle.net/3RpvJ/

I have tried to make more div’s like timer1 timer2 enz. but i cant seem to get it working

window.onload = function() {
    canvas  = document.getElementById('timer'),
    seconds = document.getElementById('counter'),
    ctx     = canvas.getContext('2d'), 
    sec     = 180,
    countdown = sec;

ctx.lineWidth = 8;
ctx.strokeStyle = "#528f20";

var 
startAngle = 0, 
time       = 0,
intv       = setInterval(function(){


    var endAngle = (Math.PI * time * 2 / sec);
    ctx.arc(65, 35, 30, startAngle , endAngle, false);
    ctx.clearRect(0, 0, 200, 200);

    startAngle = endAngle;
    ctx.stroke();

    countdown--;
    if ( countdown > 60){
    seconds.innerHTML = Math.floor(countdown/60);
    seconds.innerHTML += ":" + countdown%60;
    }
    else{
    seconds.innerHTML = countdown;
    }

    if (++time > sec,countdown == 0 ) 
    { 
        clearInterval(intv),
        $("#timer, #counter").remove(),
        $("#timers").prepend('<img id="theImg" src="http://ivojonkers.com/votify/upvote.png" />'); 
    }



}, 10);

}​

  • 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-13T15:33:58+00:00Added an answer on June 13, 2026 at 3:33 pm

    http://jsfiddle.net/3RpvJ/5/

    function Timer(dur, par, can, cnt) {
        var parent = $(par),
            canvas = can ? $(can, parent)[0] : $('.timer', parent)[0],
            seconds = cnt ? $(cnt, parent)[0] : $('.counter', parent)[0],
            //ctx = canvas.getContext('2d'),
            sec = dur,
            countdown = sec;    
    
        if (!canvas)
            canvas = $("<canvas>").addClass('timer')
                .attr('width', 100).attr('height', 100).appendTo(parent)[0];
    
        if (!seconds)
            seconds = $("<span>").addClass('counter').appendTo(parent)[0];
    
        var ctx = canvas.getContext('2d');
        ctx.lineWidth = 8;
        ctx.strokeStyle = "#528f20";
    
        var startAngle = 0,
            time = 0,
            intv = setInterval(function() {
                var endAngle = (Math.PI * time * 2 / sec);
                ctx.arc(65, 35, 30, startAngle, endAngle, false);
                ctx.clearRect(0, 0, 200, 200);
    
                startAngle = endAngle;
                ctx.stroke();
    
                countdown--;
                if (countdown > 60) {
                    seconds.innerHTML = Math.floor(countdown / 60);
                    seconds.innerHTML += ":" + countdown % 60;
                }
                else {
                    seconds.innerHTML = countdown;
                }
    
                if (++time > sec, countdown == 0) {
                    clearInterval(intv);
                    $(canvas).remove();
                    $(seconds).remove();
                    $(par).prepend('<img id="theImg" src="http://ivojonkers.com/votify/upvote.png" />');
                }
            }, 10);
    }
    
    $(function() {
        Timer(180, '#timer1');
        Timer(240, '#timer2');
        Timer(300, '#timer3');
        Timer(360, '#timer4');
    });​
    

    html:

    <div id="timers">
        <div id="timer1" class="time">
        </div>
        <div id="timer2" class="time">
        </div>
        <div id="timer3" class="time">
        </div>
        <div id="timer4" class="time">
        </div>
    </div>
    

    CSS:

    #timers canvas {
       -webkit-transform : rotate(-90deg);  
       -moz-transform : rotate(-90deg);
    }
    body{
        background-color: #242424;
    }
    #timers .time{
        position: relative; z-index: 1; height: 70px; width: 70px; }
    #timers span { 
        position   : absolute; 
        z-index    : 1; 
        top        : 50%; 
        margin-top : -0.6em;
        display    : block; 
        width      : 100%;
        text-align : center;
        height     : 1.5em;
        color      : #528f20;
        font       : 1.3em Arial;
    }
    

    I created a Timer function that will take a duration, a parent element, as well as optional selectors for the canvas and counter. If can and cnt aren’t specified, and don’t exist, it will create them. To the html, I added an extra grouping div so that all of the elements for each timer have a common parent. For the CSS, I changed your naming convention to keep it a bit more dry. Each Timer parent div will have the class “time”, but that can be whatever you want. The Timer will assume that the canvas has a class of “timer” and the time output will have a class of “counter”. These can also be whatever you want, but you’ll have to specify the parameters in that case.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
I want to show the soap response to UIWebview.. my soap response is, <p><img
Does anyone know how can I replace this 2 symbol below from the string
I need a function that will clean a strings' special characters. I do NOT
I'm having trouble keeping the paragraph square between the quote marks. In firefox the
I have thousands of HTML files to process using Groovy/Java and I need to
I'm working with an upstream system that sometimes sends me text destined for HTML/XML

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.