Commit ·
b640b0e
1
Parent(s): 482d44b
Fix scroll freeze on mobile: prevent animation observer from blocking scroll
Browse files- static/js/script.js +13 -13
static/js/script.js
CHANGED
|
@@ -33,15 +33,10 @@ document.addEventListener("DOMContentLoaded", function() {
|
|
| 33 |
|
| 34 |
// Scroll vers le haut
|
| 35 |
window.scrollTo({ top: 0, behavior: "smooth" });
|
| 36 |
-
|
| 37 |
-
// Réinitialiser les animations pour la nouvelle page
|
| 38 |
-
setTimeout(() => {
|
| 39 |
-
initScrollAnimations();
|
| 40 |
-
}, 100);
|
| 41 |
});
|
| 42 |
});
|
| 43 |
|
| 44 |
-
// Initialiser les animations au chargement
|
| 45 |
initScrollAnimations();
|
| 46 |
});
|
| 47 |
|
|
@@ -84,24 +79,29 @@ function createMobileMenuButton() {
|
|
| 84 |
});
|
| 85 |
}
|
| 86 |
|
| 87 |
-
// Fonction pour détecter les éléments visibles et les animer
|
| 88 |
function initScrollAnimations() {
|
| 89 |
const animatedElements = document.querySelectorAll('.animate-on-scroll, .animate-from-left, .animate-from-right, .animate-zoom');
|
| 90 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 91 |
const observer = new IntersectionObserver((entries) => {
|
| 92 |
entries.forEach(entry => {
|
| 93 |
if (entry.isIntersecting) {
|
|
|
|
| 94 |
entry.target.classList.add('animated');
|
|
|
|
|
|
|
| 95 |
}
|
| 96 |
});
|
| 97 |
-
},
|
| 98 |
-
threshold: 0.1,
|
| 99 |
-
rootMargin: '0px 0px -50px 0px'
|
| 100 |
-
});
|
| 101 |
|
|
|
|
| 102 |
animatedElements.forEach(element => {
|
| 103 |
-
// Retirer la classe animated pour réinitialiser
|
| 104 |
-
element.classList.remove('animated');
|
| 105 |
observer.observe(element);
|
| 106 |
});
|
| 107 |
}
|
|
|
|
| 33 |
|
| 34 |
// Scroll vers le haut
|
| 35 |
window.scrollTo({ top: 0, behavior: "smooth" });
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 36 |
});
|
| 37 |
});
|
| 38 |
|
| 39 |
+
// Initialiser les animations UNE SEULE FOIS au chargement
|
| 40 |
initScrollAnimations();
|
| 41 |
});
|
| 42 |
|
|
|
|
| 79 |
});
|
| 80 |
}
|
| 81 |
|
| 82 |
+
// Fonction pour détecter les éléments visibles et les animer - VERSION FIXÉE
|
| 83 |
function initScrollAnimations() {
|
| 84 |
const animatedElements = document.querySelectorAll('.animate-on-scroll, .animate-from-left, .animate-from-right, .animate-zoom');
|
| 85 |
|
| 86 |
+
// Options optimisées pour mobile
|
| 87 |
+
const observerOptions = {
|
| 88 |
+
threshold: 0.1,
|
| 89 |
+
rootMargin: '0px 0px -50px 0px'
|
| 90 |
+
};
|
| 91 |
+
|
| 92 |
const observer = new IntersectionObserver((entries) => {
|
| 93 |
entries.forEach(entry => {
|
| 94 |
if (entry.isIntersecting) {
|
| 95 |
+
// Ajouter la classe animated
|
| 96 |
entry.target.classList.add('animated');
|
| 97 |
+
// NE PLUS OBSERVER cet élément après animation (FIX CRITIQUE!)
|
| 98 |
+
observer.unobserve(entry.target);
|
| 99 |
}
|
| 100 |
});
|
| 101 |
+
}, observerOptions);
|
|
|
|
|
|
|
|
|
|
| 102 |
|
| 103 |
+
// Observer tous les éléments
|
| 104 |
animatedElements.forEach(element => {
|
|
|
|
|
|
|
| 105 |
observer.observe(element);
|
| 106 |
});
|
| 107 |
}
|