Skip to content

Commit 153c696

Browse files
authored
Create script.js
1 parent b809810 commit 153c696

File tree

1 file changed

+187
-0
lines changed

1 file changed

+187
-0
lines changed

script.js

Lines changed: 187 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,187 @@
1+
document.querySelectorAll('a[href^="#"]').forEach(anchor => {
2+
anchor.addEventListener('click', function (e) {
3+
e.preventDefault();
4+
const target = document.querySelector(this.getAttribute('href'));
5+
if (target) {
6+
target.scrollIntoView({
7+
behavior: 'smooth',
8+
block: 'start'
9+
});
10+
}
11+
});
12+
});
13+
const mobileMenuBtn = document.getElementById('mobile-menu-btn');
14+
const mobileMenu = document.getElementById('mobile-menu');
15+
16+
mobileMenuBtn.addEventListener('click', () => {
17+
mobileMenu.classList.toggle('hidden');
18+
});
19+
const observerOptions = {
20+
threshold: 0.1,
21+
rootMargin: '0px 0px -50px 0px'
22+
};
23+
const observer = new IntersectionObserver((entries) => {
24+
entries.forEach(entry => {
25+
if (entry.isIntersecting) {
26+
entry.target.classList.add('visible');
27+
}
28+
});
29+
}, observerOptions);
30+
document.querySelectorAll('.fade-in').forEach(el => {
31+
observer.observe(el);
32+
});
33+
function animateCounter(element, target, duration = 2000) {
34+
const start = parseInt(element.textContent) || 0;
35+
const increment = (target - start) / (duration / 50);
36+
let current = start;
37+
const timer = setInterval(() => {
38+
current += increment;
39+
if ((increment > 0 && current >= target) || (increment < 0 && current <= target)) {
40+
current = target;
41+
clearInterval(timer);
42+
}
43+
element.textContent = Math.floor(current);
44+
}, 50);
45+
}
46+
const sURL = 'https://api.allorigins.win/raw?url=http://185.44.80.38:30120';
47+
function updateStatsWithAnimation() {
48+
fetch(`${sURL}/players.json`)
49+
.then(res => res.json())
50+
.then(players => {
51+
const online = players.length;
52+
const max = 48; // 🧠 Mets ici ton slot max
53+
const counters = [
54+
{ id: 'member-count', target: max },
55+
{ id: 'online-count', target: online },
56+
{ id: 'events-count', target: 8 }, // Stat fixe ou dynamique
57+
{ id: 'missions-count', target: 45 } // Stat fixe ou dynamique
58+
];
59+
const observer = new IntersectionObserver((entries) => {
60+
entries.forEach(entry => {
61+
if (entry.isIntersecting) {
62+
const counter = counters.find(c => c.id === entry.target.id);
63+
if (counter) {
64+
animateCounter(entry.target, counter.target);
65+
observer.unobserve(entry.target);
66+
}
67+
}
68+
});
69+
}, { threshold: 0.5 });
70+
counters.forEach(counter => {
71+
const el = document.getElementById(counter.id);
72+
if (el) observer.observe(el);
73+
});
74+
})
75+
.catch(err => {
76+
console.error('Erreur fetch FiveM :', err);
77+
document.getElementById('member-count').textContent = 'N/A';
78+
document.getElementById('online-count').textContent = 'N/A';
79+
});
80+
}
81+
updateStatsWithAnimation();
82+
setInterval(updateStatsWithAnimation, 30000);
83+
window.addEventListener('scroll', () => {
84+
const scrolled = window.pageYOffset;
85+
const parallaxElements = document.querySelectorAll('.parallax');
86+
parallaxElements.forEach(element => {
87+
const speed = element.dataset.speed || 0.5;
88+
const yPos = -(scrolled * speed);
89+
element.style.transform = `translateY(${yPos}px)`;
90+
});
91+
});
92+
window.addEventListener('scroll', () => {
93+
const nav = document.querySelector('nav');
94+
if (window.scrollY > 50) {
95+
nav.classList.add('bg-gray-900', 'bg-opacity-95');
96+
} else {
97+
nav.classList.remove('bg-gray-900', 'bg-opacity-95');
98+
}
99+
});
100+
const typingText = document.querySelector('.typing-effect');
101+
if (typingText) {
102+
const text = typingText.textContent;
103+
typingText.textContent = '';
104+
let i = 0;
105+
function typeWriter() {
106+
if (i < text.length) {
107+
typingText.textContent += text.charAt(i);
108+
i++;
109+
setTimeout(typeWriter, 100);
110+
}
111+
}
112+
113+
setTimeout(typeWriter, 1000);
114+
}
115+
document.querySelectorAll('button').forEach(button => {
116+
button.addEventListener('click', function (e) {
117+
const ripple = document.createElement('span');
118+
const rect = this.getBoundingClientRect();
119+
const size = Math.max(rect.width, rect.height);
120+
const x = e.clientX - rect.left - size / 2;
121+
const y = e.clientY - rect.top - size / 2;
122+
ripple.style.width = ripple.style.height = size + 'px';
123+
ripple.style.left = x + 'px';
124+
ripple.style.top = y + 'px';
125+
ripple.classList.add('ripple');
126+
this.appendChild(ripple);
127+
setTimeout(() => {
128+
ripple.remove();
129+
}, 600);
130+
});
131+
});
132+
const cursor = document.createElement('div');
133+
cursor.classList.add('custom-cursor');
134+
document.body.appendChild(cursor);
135+
document.addEventListener('mousemove', (e) => {
136+
cursor.style.left = e.clientX + 'px';
137+
cursor.style.top = e.clientY + 'px';
138+
});
139+
document.querySelectorAll('a, button').forEach(element => {
140+
element.addEventListener('mouseenter', () => {
141+
cursor.classList.add('cursor-hover');
142+
});
143+
element.addEventListener('mouseleave', () => {
144+
cursor.classList.remove('cursor-hover');
145+
});
146+
});
147+
const preloadImages = [
148+
];
149+
preloadImages.forEach(src => {
150+
const img = new Image();
151+
img.src = src;
152+
});
153+
window.addEventListener('load', () => {
154+
document.body.classList.add('loaded');
155+
});
156+
window.addEventListener('error', (e) => {
157+
console.warn('Non-critical error:', e.message);
158+
});
159+
if ('performance' in window) {
160+
window.addEventListener('load', () => {
161+
const loadTime = performance.now();
162+
console.log(`Page loaded in ${loadTime.toFixed(2)}ms`);
163+
});
164+
}
165+
const scrollProgress = document.createElement('div');
166+
scrollProgress.classList.add('scroll-progress');
167+
document.body.appendChild(scrollProgress);
168+
window.addEventListener('scroll', () => {
169+
const scrollTop = window.pageYOffset;
170+
const documentHeight = document.documentElement.scrollHeight - window.innerHeight;
171+
const scrollPercent = (scrollTop / documentHeight) * 100;
172+
scrollProgress.style.width = scrollPercent + '%';
173+
});
174+
let konamiCode = [];
175+
const konamiSequence = [38, 38, 40, 40, 37, 39, 37, 39, 66, 65];
176+
document.addEventListener('keydown', (e) => {
177+
konamiCode.push(e.keyCode);
178+
if (konamiCode.length > konamiSequence.length) {
179+
konamiCode.shift();
180+
}
181+
if (konamiCode.join(',') === konamiSequence.join(',')) {
182+
document.body.style.filter = 'hue-rotate(180deg)';
183+
setTimeout(() => {
184+
document.body.style.filter = 'none';
185+
}, 3000);
186+
}
187+
});

0 commit comments

Comments
 (0)