JSFiddle - React, Tailwind, and code Playground
by Matt Ball
HTML
<button id="start">Start</button>
<button id="reset">Reset</button>
<span id="counter">233</span>
JavaScript
$(function ()
{
var $start = $('#start'),
start = $start.get(0),
$reset = $('#reset'),
reset = $reset.get(0),
$counter = $('#counter'),
startVal = $counter.text(),
currentVal,
endVal = 250,
prefix = '$',
fontSize = $counter.css('font-size');
$start.click(function ()
{
this.disabled = true;
currentVal = startVal;
var i = setInterval(function ()
{
if (currentVal === endVal)
{
clearInterval(i);
reset.disabled = false;
$counter.animate({fontSize: fontSize});
}
else
{
currentVal++;
$counter.text(prefix+currentVal).animate({fontSize: '+=1'}, 100);
}
}, 100);
});
$reset.click(function ()
{
$counter.text(prefix + startVal);
this.disabled = true;
start.disabled = false;
}).click();
});