mirror of
https://git.imnavajas.es/jjimenez/erp-imprimelibros.git
synced 2026-02-09 20:39:12 +00:00
34 lines
1.2 KiB
JavaScript
34 lines
1.2 KiB
JavaScript
import {formateaMoneda} from "./utils.js";
|
|
|
|
$(() => {
|
|
// Contador animado
|
|
function counter() {
|
|
var counter = document.querySelectorAll(".counter-value");
|
|
var speed = 250; // The lower the slower
|
|
counter &&
|
|
Array.from(counter).forEach(function (counter_value) {
|
|
function updateCount() {
|
|
var target = +counter_value.getAttribute("data-target");
|
|
var count = +counter_value.innerText;
|
|
var inc = target / speed;
|
|
if (inc < 1) {
|
|
inc = 1;
|
|
}
|
|
// Check if target is reached
|
|
if (count < target) {
|
|
// Add inc to count and output in counter_value
|
|
counter_value.innerText = (count + inc).toFixed(0);
|
|
// Call function every ms
|
|
setTimeout(updateCount, 1);
|
|
} else {
|
|
counter_value.innerText = formateaMoneda(target);
|
|
}
|
|
formateaMoneda(counter_value.innerText);
|
|
}
|
|
updateCount();
|
|
});
|
|
|
|
}
|
|
counter();
|
|
|
|
}) |