mirror of
https://github.com/GuerillaStudio/compteur-de-greve.git
synced 2024-12-18 05:41:56 +00:00
respect reduced motion for counter animation
This commit is contained in:
parent
419358852d
commit
a9cdc16f2a
1 changed files with 17 additions and 13 deletions
|
@ -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) {
|
||||
|
|
Loading…
Reference in a new issue