Incremento un contatore in formato testo, è possibile impostare quando deve iniziare e quando deve finire e la velocita con cui si deve incrementare.
Richiamo la libreria di jquery
<script src="http://code.jquery.com/jquery-latest.min.js" type="text/javascript"></script>
la funzione javascript
<script type="text/javascript">
$(document).ready(function(){
var start = "0100,00";
var stop = "0104,45";
var speed = 300;
var a,b,c,d,e,f;
cnt = setInterval(function() {
a = parseInt(start.charAt(0));
b = parseInt(start.charAt(1));
c = parseInt(start.charAt(2));
d = parseInt(start.charAt(3));
e = ",";
f = parseInt(start.charAt(5));
g = parseInt(start.charAt(6));
if(g >= 9) {
g = 0;
if(f >= 9) {
f = 0;
if(d >= 9) {
d = 0;
if(c >= 9) {
c = 0;
if(b >= 9) {
b = 0;
if(a >= 9) {
clearInterval(cnt);
}else{
a++;
}
}else{
b++;
}
}else{
c++;
}
}else{
d++;
}
}else{
f++;
}
} else {
g++;
}
start = String(a) + String(b) + String(c) + String(d) + String(e) + String(f) + String(g);
for ( var i = 0; i < start.length; i++ ) {
$("#s" + i).html(start.charAt(i))
}
if(start == stop) {
clearInterval(cnt);
}
},speed);
})
</script>
il codice html per il contatore
<div>
<span id="s0"></span>
<span id="s1"></span>
<span id="s2"></span>
<span id="s3"></span>
<span id="s4">,</span>
<span id="s5"></span>
<span id="s6"></span>
</div>
nell esempio ho messo un po di formattazione
<style type="text/css">
div#counter {
background-color: #000;
color: gold;
font-weight: bold;
padding:6px;
font-size: 1.8em;
font-family: Courier;
letter-spacing: -4px;
width: 200px;
text-align: center;
border:5px solid #063F86;
}
div#counter div {
padding:6px;
}
</style>