From 632986b36bccaea9a49a148d44e07fb0d90073dd Mon Sep 17 00:00:00 2001 From: Adrian Rosin Date: Fri, 2 Feb 2024 10:43:48 +0100 Subject: [PATCH] feat: added prefered reduced motion (prm) condition which triggers to directly disable the animations if the prm equals to reduce #30 --- static/script-bon.js | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/static/script-bon.js b/static/script-bon.js index c369bb1..c14fa34 100644 --- a/static/script-bon.js +++ b/static/script-bon.js @@ -1,5 +1,6 @@ -// State of the animation -let animationPaused = false; +// Checks if the user enabled or not prefers-reduced-motion +const prefersReducedMotion = window.matchMedia('(prefers-reduced-motion: reduce)').matches; + // Dictionary to keep track of animation intervals let animationIntervals = {}; // Dictionary to keep track of delay count for each animation @@ -29,8 +30,10 @@ function animate(id, delay) { frames[id] = framesList; delays[id] = delay; - // start the animation - animationIntervals[id] = setInterval(updateAnimation, delay, id, framesList, framesList.length); + // Start the animation if prefers-reduced-motion is not enabled + if (!prefersReducedMotion) { + animationIntervals[id] = setInterval(updateAnimation, delay, id, framesList, framesList.length); + } } function updateAnimation(id, framesList, totalFrames) {