anna4,
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>demo</title>
<script>
window.onload=function(){
function number_to(id,from,to,duration)
{
var element = document.getElementById(id);
var start = new Date().getTime();
setTimeout(function() {
var now = (new Date().getTime()) - start;
var progress = now / duration;
var result = Math.floor((to - from) * progress + from);
element.innerHTML = progress < 1 ? result : to;
if (progress < 1) setTimeout(arguments.callee, 10);
}, 10);
}
document.querySelector('#but').addEventListener('click', function() {
number_to("example",900,1500,3000);
number_to("test",10,-5,15000)
});
};
</script>
</head>
<body>
<div id="example"></div>
<div id="test"></div>
<input id="but" name="" type="button" value="это кнопа">
</body>
</html>