-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
100 lines (83 loc) · 3.52 KB
/
Copy pathscript.js
File metadata and controls
100 lines (83 loc) · 3.52 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
document.addEventListener('DOMContentLoaded', () => {
// Set current year in footer
document.getElementById('year').textContent = new Date().getFullYear();
// Navbar scroll effect
const navbar = document.querySelector('.navbar');
window.addEventListener('scroll', () => {
if (window.scrollY > 50) {
navbar.classList.add('scrolled');
} else {
navbar.classList.remove('scrolled');
}
});
// Animate numbers
const stats = document.querySelectorAll('.stat-number');
let hasAnimated = false;
const animateStats = () => {
stats.forEach(stat => {
const target = +stat.getAttribute('data-target');
const duration = 2000; // ms
const step = target / (duration / 16); // 60fps
let current = 0;
const updateStat = () => {
current += step;
if (current < target) {
stat.textContent = Math.ceil(current);
requestAnimationFrame(updateStat);
} else {
stat.textContent = target;
}
};
updateStat();
});
};
// Check if stats section is in view to trigger animation
const observer = new IntersectionObserver((entries) => {
if (entries[0].isIntersecting && !hasAnimated) {
hasAnimated = true;
animateStats();
}
}, { threshold: 0.5 });
const statsSection = document.querySelector('.hero-stats');
if (statsSection) {
observer.observe(statsSection);
}
// Smooth scroll for anchor links
document.querySelectorAll('a[href^="#"]').forEach(anchor => {
anchor.addEventListener('click', function (e) {
e.preventDefault();
const targetId = this.getAttribute('href');
if (targetId === '#') return;
const targetElement = document.querySelector(targetId);
if (targetElement) {
// Adjust for fixed navbar height
const navHeight = document.querySelector('.navbar').offsetHeight;
const targetPosition = targetElement.getBoundingClientRect().top + window.pageYOffset - navHeight;
window.scrollTo({
top: targetPosition,
behavior: 'smooth'
});
}
});
});
// Mouse movement effect on hero visual
const heroVisual = document.querySelector('.hero-visual');
const codeWindow = document.querySelector('.code-window');
if (heroVisual && codeWindow) {
heroVisual.addEventListener('mousemove', (e) => {
const rect = heroVisual.getBoundingClientRect();
const x = e.clientX - rect.left; // x position within the element.
const y = e.clientY - rect.top; // y position within the element.
const centerX = rect.width / 2;
const centerY = rect.height / 2;
// Calculate rotation based on mouse position relative to center
const rotateX = ((y - centerY) / centerY) * 10;
const rotateY = ((centerX - x) / centerX) * 10;
codeWindow.style.transform = `rotateX(${rotateX}deg) rotateY(${rotateY}deg)`;
});
heroVisual.addEventListener('mouseleave', () => {
// Reset to default
codeWindow.style.transform = 'rotateY(-15deg) rotateX(5deg)';
});
}
});