Countdown Timer - Animation Idea #13

  • 30 August 2022
  • 2 replies
  • 70 views

Userlevel 7
Badge +5

I came across an animation that I thought was pretty cool and I decided I would try to recreate the effect for use with Docebo.

This is an animated countdown timer - currently only 9 to 0 - I suppose you could have it count up as well. It uses two black divs over the top of a greenyellow div. The two black divs simply animate to different locations within the green div to mask portions of it out so that the result is a number showing through.

The animation lasts for 10 seconds as you might imagine.

Here is the code for you to play with and tweak as desired. As usual - there are two parts - CSS and HTML.

First the CSS

/** This is a countdown timer **/

/** This sets the size and color of your overall background **/
.digitBG {
background-color: black;
width: 70px;
height: 90px;
position: absolute;
}

/** This sets the size, color, and start position of your number digit **/
.digit {
height: 50px;
width: 30px;
background-color: greenyellow;
position: relative;
top: 20px;
left: 20px;
}

/** These are shared parameters of both masks **/
.mask1, .mask2 {
background-color: black;
animation-duration: 10s;
position: absolute;
animation-iteration-count: infinite;
}

/** This associates the animation to the div **/
.mask1 {
animation-name: moveMask1;
}

/** This associates the animation to the div **/
.mask2 {
animation-name: moveMask2;
}

/** This is the movement of mask1 from 9 to 0 **/
@keyframes moveMask1 {
0% {top: 10px; left: 10px; height: 10px; width: 10px;}
9% {top: 10px; left: 10px; height: 10px; width: 10px;}
10% {top: 10px; left: 10px; height: 10px; width: 10px;}
19% {top: 10px; left: 10px; height: 10px; width: 10px;}
20% {top: 10px; left: 0px; height: 15px; width: 20px;}
29% {top: 10px; left: 0px; height: 15px; width: 20px;}
30% {top: 10px; left: 10px; height: 10px; width: 20px;}
39% {top: 10px; left: 10px; height: 10px; width: 20px;}
40% {top: 10px; left: 10px; height: 10px; width: 20px;}
49% {top: 10px; left: 10px; height: 10px; width: 20px;}
50% {top: 0px; left: 10px; height: 20px; width: 10px;}
59% {top: 0px; left: 10px; height: 20px; width: 10px;}
60% {top: 10px; left: 0px; height: 10px; width: 20px;}
69% {top: 10px; left: 0px; height: 10px; width: 20px;}
70% {top: 10px; left: 0px; height: 10px; width: 20px;}
79% {top: 10px; left: 0px; height: 10px; width: 20px;}
80% {top: 0px; left: 0px; height: 25px; width: 20px;}
89% {top: 0px; left: 0px; height: 25px; width: 20px;}
90% {top: 10px; left: 10px; height: 15px; width: 10px;}
99% {top: 10px; left: 10px; height: 15px; width: 10px;}
100% {top: 10px; left: 10px; height: 10px; width: 10px;}
}

/** This is the movement of mask2 from 9 to 0 **/
@keyframes moveMask2 {
0% {top: 30px; left: 0px; height: 10px; width: 20px;}
9% {top: 30px; left: 0px; height: 10px; width: 20px;}
10% {top: 30px; left: 10px; height: 10px; width: 10px;}
19% {top: 30px; left: 10px; height: 10px; width: 10px;}
20% {top: 25px; left: 0px; height: 25px; width: 20px;}
29% {top: 25px; left: 0px; height: 25px; width: 20px;}
30% {top: 30px; left: 10px; height: 10px; width: 10px;}
39% {top: 30px; left: 10px; height: 10px; width: 10px;}
40% {top: 30px; left: 0px; height: 10px; width: 20px;}
49% {top: 30px; left: 0px; height: 10px; width: 20px;}
50% {top: 30px; left: 0px; height: 20px; width: 20px;}
59% {top: 30px; left: 0px; height: 20px; width: 20px;}
60% {top: 30px; left: 0px; height: 10px; width: 20px;}
69% {top: 30px; left: 0px; height: 10px; width: 20px;}
70% {top: 30px; left: 10px; height: 10px; width: 20px;}
79% {top: 30px; left: 10px; height: 10px; width: 20px;}
80% {top: 25px; left: 0px; height: 25px; width: 20px;}
89% {top: 25px; left: 0px; height: 25px; width: 20px;}
90% {top: 25px; left: 10px; height: 15px; width: 10px;}
99% {top: 25px; left: 10px; height: 15px; width: 10px;}
100% {top: 30px; left: 0px; height: 10px; width: 20px;}
}

The HTML is really simple.

<!-- Place the divs in your widget -->
<!-- Make sure the two masks are in the digit div -->

<div class="digitBG">
<div class="digit">
<div class="mask1"></div>
<div class="mask2"></div>
</div>
</div>

Hopefully this will add some fun to someone’s day!

I would love to hear how you have used this idea - please share below.


2 replies

Userlevel 7
Badge +6

@gstager- very neat. It would be nice to leverage a variant like this for a Compliance count down timer. Unfortunately - even saying what I am saying? I realize that you have the browser counting seconds….that aint gonna work with the type of count down timer I am describing.

There are ALOT of HTML 5 timers/clocks out there and one freebie that I know of that can be nicely iframed in is:

https://www.timeanddate.com/clocks/freecountdown.html

Userlevel 7
Badge +5

@dklinger 

Yeah - the ol’ iFrame trick - to bring in nicer stuff made with more than HTML and CSS

I get it…

If this never makes it on another Docebo platform ever but it helps to inspire someone to learn more about how to improve their CSS skills. It was worth it.

Reply