-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.js
More file actions
180 lines (146 loc) · 4.89 KB
/
Copy pathmain.js
File metadata and controls
180 lines (146 loc) · 4.89 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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
/* ============================================================
DevOps World — main.js
Scroll reveal, micro-interactions & smooth UX behaviors
============================================================ */
// ---------- Scroll Reveal ----------
const revealObserver = new IntersectionObserver(
(entries) => {
entries.forEach((entry) => {
if (entry.isIntersecting) {
entry.target.classList.add('visible');
revealObserver.unobserve(entry.target);
}
});
},
{ threshold: 0.12 }
);
document.querySelectorAll('.reveal').forEach((el) => revealObserver.observe(el));
// ---------- Nav scroll shadow ----------
const nav = document.querySelector('nav');
window.addEventListener('scroll', () => {
if (window.scrollY > 20) {
nav.style.boxShadow = '0 4px 24px rgba(0,0,0,0.35)';
} else {
nav.style.boxShadow = 'none';
}
}, { passive: true });
// ---------- Smooth scroll for anchor links ----------
document.querySelectorAll('a[href^="#"]').forEach((anchor) => {
anchor.addEventListener('click', (e) => {
e.preventDefault();
const target = document.querySelector(anchor.getAttribute('href'));
if (target) {
target.scrollIntoView({ behavior: 'smooth', block: 'start' });
}
});
});
// ---------- Button ripple effect ----------
function createRipple(event) {
const button = event.currentTarget;
const existing = button.querySelector('.ripple');
if (existing) existing.remove();
const circle = document.createElement('span');
const diameter = Math.max(button.clientWidth, button.clientHeight);
const radius = diameter / 2;
const rect = button.getBoundingClientRect();
circle.style.cssText = `
width: ${diameter}px;
height: ${diameter}px;
left: ${event.clientX - rect.left - radius}px;
top: ${event.clientY - rect.top - radius}px;
position: absolute;
border-radius: 50%;
background: rgba(255,255,255,0.25);
transform: scale(0);
animation: ripple-anim 0.55s linear;
pointer-events: none;
`;
circle.classList.add('ripple');
button.style.position = 'relative';
button.style.overflow = 'hidden';
button.appendChild(circle);
circle.addEventListener('animationend', () => circle.remove());
}
// Inject ripple keyframes once
const rippleStyle = document.createElement('style');
rippleStyle.textContent = `
@keyframes ripple-anim {
to { transform: scale(3); opacity: 0; }
}
`;
document.head.appendChild(rippleStyle);
document.querySelectorAll('.btn-primary, .btn-secondary, .nav-cta').forEach((btn) => {
btn.addEventListener('click', createRipple);
});
// ---------- Animated stat counter ----------
function animateCounter(el, target, suffix = '', duration = 1400) {
const isDecimal = target % 1 !== 0;
const start = performance.now();
function step(now) {
const elapsed = now - start;
const progress = Math.min(elapsed / duration, 1);
// Ease out cubic
const eased = 1 - Math.pow(1 - progress, 3);
const value = eased * target;
el.textContent = isDecimal
? value.toFixed(1) + suffix
: Math.round(value) + suffix;
if (progress < 1) requestAnimationFrame(step);
}
requestAnimationFrame(step);
}
const statObserver = new IntersectionObserver(
(entries) => {
entries.forEach((entry) => {
if (!entry.isIntersecting) return;
const el = entry.target;
const raw = el.dataset.target;
const suffix = el.dataset.suffix || '';
const target = parseFloat(raw);
animateCounter(el, target, suffix);
statObserver.unobserve(el);
});
},
{ threshold: 0.5 }
);
// Wire up stat numbers — read from data attributes
document.querySelectorAll('.stat-num').forEach((el) => {
const text = el.textContent.trim();
// Parse value and suffix from existing text
const match = text.match(/^([\d.]+)(.*)$/);
if (!match) return;
const value = match[1];
const suffix = match[2];
el.dataset.target = value;
el.dataset.suffix = suffix;
el.textContent = '0' + suffix;
statObserver.observe(el);
});
// ---------- Pipeline step active highlight on scroll ----------
const pipeSteps = document.querySelectorAll('.pipe-step');
const pipeObserver = new IntersectionObserver(
(entries) => {
entries.forEach((entry) => {
if (entry.isIntersecting) {
let delay = 0;
pipeSteps.forEach((step) => {
setTimeout(() => {
step.style.transition = 'background 0.3s, opacity 0.4s, transform 0.4s';
step.style.opacity = '1';
step.style.transform = 'translateY(0)';
}, delay);
delay += 120;
});
pipeObserver.unobserve(entry.target);
}
});
},
{ threshold: 0.3 }
);
// Set initial hidden state for pipeline steps
pipeSteps.forEach((step) => {
step.style.opacity = '0';
step.style.transform = 'translateY(12px)';
});
const pipelineEl = document.querySelector('.pipeline');
if (pipelineEl) pipeObserver.observe(pipelineEl);