1
0
Fork 0
mirror of https://github.com/GuerillaStudio/compteur-de-greve.git synced 2024-10-09 05:19:02 +00:00

respect reduced motion for counter animation

This commit is contained in:
wryk 2023-03-02 07:38:31 +01:00
parent 419358852d
commit a9cdc16f2a

View file

@ -67,22 +67,26 @@ document.addEventListener('alpine:init', () => {
})
function animateRange(duration, start, end, callback) {
let startTimestamp = null;
if (matchMedia("(prefers-reduced-motion)").matches) {
callback(end)
} else {
let startTimestamp = null;
const step = (timestamp) => {
if (!startTimestamp) {
startTimestamp = timestamp
const step = (timestamp) => {
if (!startTimestamp) {
startTimestamp = timestamp
};
const progress = Math.min((timestamp - startTimestamp) / duration, 1)
callback(Math.floor(progress * (end - start) + start))
if (progress < 1) {
requestAnimationFrame(step)
}
};
const progress = Math.min((timestamp - startTimestamp) / duration, 1)
callback(Math.floor(progress * (end - start) + start))
if (progress < 1) {
requestAnimationFrame(step)
}
};
requestAnimationFrame(step);
requestAnimationFrame(step)
}
}
function formatNumber(number) {