feat: smooth scroll animation and back-to-top button

This commit is contained in:
2026-05-18 17:49:27 +04:00
parent 5c3b35cb3c
commit 6f5c2f5177
2 changed files with 135 additions and 83 deletions
+63
View File
@@ -406,6 +406,50 @@ document.addEventListener('DOMContentLoaded', function() {
});
});
// Scroll animé vers les sections depuis les badges hero et les liens de navigation
document.querySelectorAll('a[href^="#"]').forEach(function(link) {
link.addEventListener('click', function(e) {
const targetId = this.getAttribute('href').slice(1);
const target = document.getElementById(targetId);
if (!target) return;
e.preventDefault();
// Fermer le menu mobile si ouvert
if (mobileMenu && mobileMenu.classList.contains('active')) {
mobileMenu.classList.remove('active');
document.body.style.overflow = '';
}
const offset = 24;
const top = target.getBoundingClientRect().top + window.scrollY - offset;
window.scrollTo({ top: top, behavior: 'smooth' });
// Highlight de la section à l'arrivée
const duration = Math.min(
600 + Math.abs(top - window.scrollY) / 4,
1200
);
setTimeout(function() {
target.classList.add('section-arrive');
setTimeout(function() { target.classList.remove('section-arrive'); }, 900);
}, duration);
});
});
// Bouton retour en haut
const backToTop = document.getElementById('back-to-top');
if (backToTop) {
window.addEventListener('scroll', function() {
backToTop.classList.toggle('visible', window.scrollY > 300);
}, { passive: true });
backToTop.addEventListener('click', function() {
window.scrollTo({ top: 0, behavior: 'smooth' });
});
}
// Scroll vers le haut avec effet moderne quand on clique sur le logo du footer
const footerLogo = document.querySelector('.footer-logo');
if (footerLogo) {
@@ -416,4 +460,23 @@ document.addEventListener('DOMContentLoaded', function() {
});
});
}
// Auto-resize des iframes de profil social (TikTok, Instagram)
// Ces plateformes envoient des postMessage avec leur hauteur réelle
window.addEventListener('message', function(e) {
if (!e.data || !e.origin) return;
try {
const data = typeof e.data === 'string' ? JSON.parse(e.data) : e.data;
const height = data.height ?? data.contentHeight ?? data['height'];
if (!height || typeof height !== 'number' || height < 100) return;
document.querySelectorAll('.platform-profile-iframe').forEach(function(iframe) {
try {
if (new URL(iframe.src).origin === e.origin) {
iframe.style.height = Math.ceil(height) + 'px';
}
} catch (_) {}
});
} catch (_) {}
});
});