-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
64 lines (51 loc) · 1.98 KB
/
index.js
File metadata and controls
64 lines (51 loc) · 1.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
function smoothScrollTo(target, duration = 1200) {
const start = window.pageYOffset;
const end = target.getBoundingClientRect().top + start - 80; // -80px pour compenser la navbar
const distance = end - start;
let startTime = null;
function animation(currentTime) {
if (!startTime) startTime = currentTime;
const timeElapsed = currentTime - startTime;
const progress = Math.min(timeElapsed / duration, 1);
// Easing (accélère puis ralentit)
const ease = progress < 0.5
? 4 * progress * progress * progress
: 1 - Math.pow(-2 * progress + 2, 3) / 2;
window.scrollTo(0, start + distance * ease);
if (timeElapsed < duration) requestAnimationFrame(animation);
}
requestAnimationFrame(animation);
}
// Dark/Light toggle
const toggle = document.getElementById("theme-toggle");
toggle.addEventListener("click", () => {
const currentTheme = document.documentElement.getAttribute("data-theme");
const newTheme = currentTheme === "light" ? "dark" : "light";
document.documentElement.setAttribute("data-theme", newTheme);
toggle.textContent = newTheme === "light" ? "🌞" : "🌙";
});
// Scroll animation
const sections = document.querySelectorAll('.section');
// Smooth scroll pour les liens du navbar
document.querySelectorAll('.navbar a[href^="#"]').forEach(anchor => {
anchor.addEventListener('click', function(e) {
e.preventDefault();
const target = document.querySelector(this.getAttribute('href'));
smoothScrollTo(target, 1500); // défilement en 1,5s
});
});
const observer = new IntersectionObserver(entries => {
entries.forEach(entry => {
if (entry.isIntersecting) {
entry.target.classList.add('visible');
// Stagger des enfants
const items = entry.target.querySelectorAll('.animate-item');
items.forEach((item, i) => {
item.style.transitionDelay = `${i * 0.2}s`; // 0.2s entre chaque
});
}
});
}, { threshold: 0.1 });
sections.forEach(section => {
observer.observe(section);
});