-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
86 lines (76 loc) · 2.83 KB
/
script.js
File metadata and controls
86 lines (76 loc) · 2.83 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
document.addEventListener('DOMContentLoaded', function () {
// Mobile Navigation Toggle
const navToggle = document.querySelector('.mobile-nav-toggle');
const mainNav = document.querySelector('.main-nav');
if(navToggle) {
navToggle.addEventListener('click', () => {
mainNav.classList.toggle('active');
});
}
// Header scroll effect
const header = document.querySelector('header');
window.addEventListener('scroll', () => {
if(window.scrollY > 50) {
header.classList.add('scrolled');
} else {
header.classList.remove('scrolled');
}
});
// Animate headline text
const headline = document.querySelector('.hero-headline');
if (headline) {
const text = headline.textContent;
headline.innerHTML = '';
text.split('').forEach((char, index) => {
const span = document.createElement('span');
span.className = 'char';
span.textContent = char === ' ' ? '\u00A0' : char; // Non-breaking space
span.style.animationDelay = `${index * 0.03}s`;
headline.appendChild(span);
});
}
// Intersection Observer for animations
const animatedSections = document.querySelectorAll('.animated-section');
const observer = new IntersectionObserver((entries, observer) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
entry.target.classList.add('visible');
if(entry.target.id === 'stats') {
startCounters();
}
observer.unobserve(entry.target);
}
});
}, {
root: null,
threshold: 0.1
});
animatedSections.forEach(section => {
observer.observe(section);
});
// Statistics counter animation
let countersStarted = false;
function startCounters() {
if (countersStarted) return;
countersStarted = true;
const counters = document.querySelectorAll('.stat-number');
counters.forEach(counter => {
const target = +counter.getAttribute('data-target');
const duration = 2000;
animateValue(counter, 0, target, duration);
});
}
function animateValue(element, start, end, duration) {
let startTimestamp = null;
const step = (timestamp) => {
if (!startTimestamp) startTimestamp = timestamp;
const progress = Math.min((timestamp - startTimestamp) / duration, 1);
const value = Math.floor(progress * (end - start) + start);
element.innerHTML = value.toLocaleString();
if (progress < 1) {
window.requestAnimationFrame(step);
}
};
window.requestAnimationFrame(step);
}
});