Add animated counter to petition map

Update petition map counter to show animated count of signatures
with matching timing to dot animation and improved text formatting

Remove redundant header styles from CSS
Move counter styling to dedicated CSS section

Update counter text to be more concise and present tense
This commit is contained in:
Ruben 2026-02-26 22:21:41 +01:00
parent bd993ea6ca
commit e8919e5842
3 changed files with 31 additions and 21 deletions

View file

@ -264,9 +264,28 @@
function updateCountLabel(total) {
const el = document.getElementById('petition-map-count');
if (!el) return;
el.textContent = total === 1
? '1 person har signert fra hele Norge'
: `${total.toLocaleString('nb-NO')} personer har signert fra hele Norge`;
// Count up animation to match dot animation
let current = 0;
const target = total;
const duration = 30000; // Same as dot animation
const startTime = performance.now();
function updateCounter(timestamp) {
const elapsed = timestamp - startTime;
const progress = Math.min(elapsed / duration, 1);
current = Math.floor(progress * target);
el.textContent = current === 1
? '1 person har signert så langt'
: `${current} personer har signert så langt`;
if (progress < 1) {
requestAnimationFrame(updateCounter);
}
}
requestAnimationFrame(updateCounter);
}
/** Initial render: place all dots with one smooth staggered animation */