I made two simple counters with jQuery. Now I try to chance the appearance of these counters.
My first counter looks like "23000" right now. But for a better overview I'd like to add a dot. "23.000" I already tried do pretend it as a decimal number: Counting up to 23 with 3 digits but then the counters starts with "0.000" and it doesn't show the "000" after finished.
Second: My counter looks like "15.06" and I'd like to change the dot with a comma like: "15,06"
Can someone help me?
jQuery(document).ready(function () {
function counter01() {
$('#01').each(function () {
var start = $(this).data("start")
var speed = $(this).data("speed")
$("#01").prop('end', start).animate({
end: $(this).data("end")
}, {
duration: speed,
step: function (now) {
$(this).text(Math.round(now * 1) / 1);
}
});
});
}
counter01();
function counter02() {
$('#02').each(function () {
var start = $(this).data("start")
var speed = $(this).data("speed")
$("#02").prop('end', start).animate({
end: $(this).data("end")
}, {
duration: speed,
step: function (now) {
$(this).text(Math.round(now * 100) / 100);
}
});
});
}
counter02();
function counter03() {
$('#03').each(function () {
var start = $(this).data("start")
var speed = $(this).data("speed")
$("#03").prop('end', start).animate({
end: $(this).data("end")
}, {
duration: speed,
step: function (now) {
$(this).text(Math.round(now * 1000) / 1000);
}
});
});
}
counter03();
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<body>
<div class="wrapper" style=" width: 30%; margin: 10px auto;float:left;">
<p style="font-size: 2em;text-align: center;line-height: 1.23em;margin: 5px;">How it looks right now</p>
<h3 id="01" class="zaehler" data-start="0" data-end="23000" data-speed="5000" style="font-size: 3em;line-height: 1em;color: red;text-align: center;margin: 5px;">23000</h3>
<h3 id="03" class="zaehler" data-start="0" data-end="23.000" data-speed="5000" style="font-size: 3em;line-height: 1em;color: red;text-align: center;margin: 5px;">23.000</h3>
<p> </p>
<p style="font-size: 2em;text-align: center;line-height: 1.23em;margin: 5px;">How it should look</p>
<h3 class="" data-start="0" data-end="23000" data-speed="3000" style="font-size: 3em;line-height: 1em;color: green;text-align: center;margin: 5px;">23.000</h3>
</div>
<div class="wrapper" style=" width: 30%; margin: 10px auto;float:left;">
<p style="font-size: 2em;text-align: center;line-height: 1.23em;margin: 5px;">How it looks right now</p>
<h3 id="02" class="zaehler" data-start="0" data-end="15.06" data-speed="2000" style="font-size: 3em;line-height: 1em;color: red;text-align: center;margin: 5px;">15,06</h3>
<p> </p>
<p style="font-size: 2em;text-align: center;line-height: 1.23em;margin: 5px;">How it should look</p>
<h3 class="" data-start="0" data-end="23000" data-speed="3000" style="font-size: 3em;line-height: 1em;color: green;text-align: center;margin: 5px;">15,06</h3>
</div>
</body>