WIP : quelques corrections, et un début de booléen 'animationEnabled' qui doit déterminer si l'on anime ou pas la page, en s'y prenant au plus tôt : pas de code appelé si pas d'animation demandée, et arrêt auto de l'animation si on toggle le booléen

This commit is contained in:
ADRN 2024-02-15 15:33:38 +01:00
parent 63176f8e97
commit d30acf4e37
2 changed files with 23 additions and 22 deletions

View file

@ -47,7 +47,7 @@
<body> <body>
<nav role="none" aria-label="boutton activer/desactiver les animations" id="play"> <nav role="none" aria-label="boutton activer/desactiver les animations" id="play">
<ul aria-label="boutton activer/desactiver les animations" role="toolbar" class="toggleButton"> <ul aria-label="bouton activer/desactiver les animations" role="toolbar" class="toggleButton">
<li role="none"> <li role="none">
<pre class="toggleable" aria-hidden="true"> <pre class="toggleable" aria-hidden="true">
|‾‾‾‾‾‾‾‾‾| |‾‾‾‾‾‾‾‾‾|

View file

@ -2,6 +2,7 @@ async function setupPage() {
// Checks if the user enabled prefers-reduced-motion // Checks if the user enabled prefers-reduced-motion
const prefersReducedMotion = window.matchMedia('(prefers-reduced-motion: reduce)').matches; const prefersReducedMotion = window.matchMedia('(prefers-reduced-motion: reduce)').matches;
let animationEnabled = prefersReducedMotion;
// Dictionary to keep track of animation intervals // Dictionary to keep track of animation intervals
let animationIntervals = {}; let animationIntervals = {};
// Dictionary to keep track of delay count for each animation // Dictionary to keep track of delay count for each animation
@ -17,8 +18,8 @@ async function setupPage() {
const parterre = document.getElementById('parterre'); const parterre = document.getElementById('parterre');
// Update ARIA live attributes based on prefers-reduced-motion // Update ARIA live attributes based on prefers-reduced-motion
function updateARIALiveAttributes() { function setARIALiveAttributes(isAnimated) {
if (prefersReducedMotion) { if (isAnimated) {
illustrationAccueil.setAttribute('aria-live', 'off'); illustrationAccueil.setAttribute('aria-live', 'off');
rennes.setAttribute('aria-live', 'off'); rennes.setAttribute('aria-live', 'off');
orsay.setAttribute('aria-live', 'off'); orsay.setAttribute('aria-live', 'off');
@ -52,13 +53,11 @@ async function setupPage() {
delays[id] = delay; delays[id] = delay;
// Update ARIA live attributes // Update ARIA live attributes
updateARIALiveAttributes(); setARIALiveAttributes(true);
// Start the animation if prefers-reduced-motion is not enabled // Start the animation if prefers-reduced-motion is not enabled
if (!prefersReducedMotion) {
animationIntervals[id] = setInterval(updateAnimation, delay, id, framesList, framesList.length); animationIntervals[id] = setInterval(updateAnimation, delay, id, framesList, framesList.length);
} }
}
function updateAnimation(id, framesList, totalFrames) { function updateAnimation(id, framesList, totalFrames) {
@ -76,10 +75,12 @@ async function setupPage() {
} }
} }
if (animationEnabled) {
animate("illustration-accueil", 500); animate("illustration-accueil", 500);
animate("rennes", 1000); animate("rennes", 1000);
animate("orsay", 2000); animate("orsay", 2000);
animate("parterre", 1500); animate("parterre", 1500);
}
const toggleableElements = document.querySelectorAll('.toggleable, .img_top_toggleable'); const toggleableElements = document.querySelectorAll('.toggleable, .img_top_toggleable');
toggleableElements.forEach(function (element) { toggleableElements.forEach(function (element) {