-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
135 lines (119 loc) · 3.96 KB
/
script.js
File metadata and controls
135 lines (119 loc) · 3.96 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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
/* CURSOR PERSONNALISÉ */
const cur = document.getElementById('cur');
const ring = document.getElementById('ring');
let mx = 0,
my = 0,
rx = 0,
ry = 0;
document.addEventListener('mousemove', e => {
mx = e.clientX;
my = e.clientY;
});
(function tick() {
cur.style.left = mx + 'px';
cur.style.top = my + 'px';
rx += (mx - rx) * .12;
ry += (my - ry) * .12;
ring.style.left = rx + 'px';
ring.style.top = ry + 'px';
requestAnimationFrame(tick);
})();
document.querySelectorAll('a, button, .toggle, .project-item, .cl, .track-pill').forEach(el => {
el.addEventListener('mouseenter', () => {
ring.style.width = '46px';
ring.style.height = '46px';
ring.style.borderColor = 'rgba(0,229,160,.7)';
});
el.addEventListener('mouseleave', () => {
ring.style.width = '32px';
ring.style.height = '32px';
ring.style.borderColor = 'rgba(0,229,160,.4)';
});
});
/* TOGGLE THÈME DARK / LIGHT */
const html = document.documentElement;
const btn = document.getElementById('toggleBtn');
const lbl = document.getElementById('themeLbl');
const saved = localStorage.getItem('theme') || 'dark';
html.setAttribute('data-theme', saved);
lbl.textContent = saved;
btn.addEventListener('click', () => {
const next = html.getAttribute('data-theme') === 'dark' ? 'light' : 'dark';
html.setAttribute('data-theme', next);
localStorage.setItem('theme', next);
lbl.textContent = next;
});
btn.addEventListener('keydown', e => {
if (e.key === 'Enter' || e.key === ' ') btn.click();
});
/*SCROLL REVEAL*/
const observer = new IntersectionObserver(entries => {
entries.forEach(entry => {
if (entry.isIntersecting) {
entry.target.classList.add('in');
observer.unobserve(entry.target);
}
});
}, { threshold: 0.1 });
document.querySelectorAll('.sr').forEach(el => observer.observe(el));
/* LIEN NAV ACTIF AU SCROLL */
const sections = document.querySelectorAll('section[id]');
const navLinks = document.querySelectorAll('.nav-links a');
window.addEventListener('scroll', () => {
let current = '';
sections.forEach(section => {
if (window.scrollY >= section.offsetTop - 110) {
current = section.id;
}
});
navLinks.forEach(a => {
a.classList.toggle('active', a.getAttribute('href') === '#' + current);
});
}, { passive: true });
/* FORMULAIRE DE CONTACT */
document.getElementById('sendBtn').addEventListener('click', async() => {
const name = document.getElementById('fn').value.trim();
const email = document.getElementById('fe').value.trim();
const subject = document.getElementById('fs').value.trim();
const msg = document.getElementById('fm').value.trim();
if (!name || !email || !msg) {
showToast('⚠ Remplissez les champs obligatoires');
return;
}
if (!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(email)) {
showToast('⚠ Email invalide');
return;
}
const endpoint = "https://formspree.io/f/myknvnqb";
try {
const response = await fetch(endpoint, {
method: "POST",
headers: {
"Accept": "application/json",
"Content-Type": "application/json"
},
body: JSON.stringify({
nom: name,
email: email,
sujet: subject,
message: msg
})
});
if (response.ok) {
showToast('✓ Message envoyé !');
['fn', 'fe', 'fs', 'fm'].forEach(id => {
document.getElementById(id).value = '';
});
} else {
showToast('⚠ Erreur lors de l\'envoi du message');
}
} catch (error) {
showToast('⚠ Erreur réseau de connexion');
}
});
function showToast(msg) {
const toast = document.getElementById('toast');
toast.textContent = msg;
toast.classList.add('show');
setTimeout(() => toast.classList.remove('show'), 3000);
}