thystruby,
<!DOCTYPE HTML>
<html>
<head>
<title>Untitled</title>
<meta charset="utf-8">
<style type="text/css">
.time{
background-color: rgb(51, 153, 0);
color: rgb(102, 255, 255);
padding: 4px 8px;
font-size: 24px;
border-radius: 4px;
}
.test{
background-color: transparent;
color: #FF0000;
}
</style>
</head>
<body>
<input id="go" name="" type="button" value="go" >
<span class="time">0</span>
<script>
function timer(b) {
return {
play: function() {
var d = performance.now();
c = !0;
requestAnimationFrame(function e(a) {
a = (a - d) / b.duration;
1 <= a && (a = 1, b.callback && b.callback());
b.elem.innerHTML = b.from + (b.to - b.from) * a | 0;
1 > a && requestAnimationFrame(e)
})
}
}
};
var span = document.querySelector('.time'),
but = document.querySelector('#go'),
anim = timer({
from : 3,
to : 0,
duration: 2 * 1000,
elem : span,
callback : function() { this.elem.classList.add('test')}
});
but.addEventListener('mousedown', anim.play);
</script>
</body>
</html>