This repository was archived by the owner on Jun 2, 2026. It is now read-only.
forked from prantomollick/saas-landing-page-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
232 lines (198 loc) · 8.11 KB
/
Copy pathscript.js
File metadata and controls
232 lines (198 loc) · 8.11 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
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
document.addEventListener("DOMContentLoaded", () => {
/**
* Handles the hero section's mouse-move parallax effect.
*/
const initHeroParallax = () => {
const heroGraphics = document.querySelector(".hero-graphics");
if (!heroGraphics) return;
// Don't run on mobile where it's not visible
if (window.innerWidth < 768) return;
document.addEventListener("mousemove", (e) => {
const { clientX, clientY } = e;
const { innerWidth, innerHeight } = window;
// Calculate movement based on cursor position from center
// The division by 50 and 30 controls the "intensity" of the effect
const moveX = (clientX - innerWidth / 2) / 50;
const moveY = (clientY - innerHeight / 2) / 30;
heroGraphics.style.transform = `translate(${moveX}px, ${moveY}px)`;
});
};
/**
* Handles the hero section's multi-layered 3D parallax effect.
*/
const initHero3DParallax = () => {
const heroSection = document.querySelector("#hero");
const graphicsContainer = document.querySelector(
".hero-graphics-container"
);
if (!heroSection || !graphicsContainer) return;
// Don't run on mobile where graphics are hidden
if (window.innerWidth < 768) return;
heroSection.addEventListener("mousemove", (e) => {
// Get cursor position relative to the center of the viewport
const { clientX, clientY } = e;
const centerX = window.innerWidth / 2;
const centerY = window.innerHeight / 2;
const moveX = (clientX - centerX) / 20; // Intensity factor
const moveY = (clientY - centerY) / 20;
// Apply transform to the whole container for a base movement
graphicsContainer.style.transform = `translate(${moveX}px, ${moveY}px)`;
// Apply individual transforms to each graphic element for depth
const graphicElements =
graphicsContainer.querySelectorAll(".graphic-element");
graphicElements.forEach((el) => {
const depth = parseFloat(el.dataset.depth) || 0;
const elMoveX = moveX * depth;
const elMoveY = moveY * depth;
el.style.transform = `translate(${elMoveX}px, ${elMoveY}px)`;
});
});
};
/**
* Handles mobile navigation toggle.
*/
const initMobileNav = () => {
const menuToggle = document.getElementById("menu-toggle");
const navMenuWrapper = document.querySelector(".nav-menu-wrapper");
const navLinks = document.querySelectorAll(".nav-link");
if (menuToggle && navMenuWrapper) {
menuToggle.addEventListener("click", () => {
menuToggle.classList.toggle("active");
navMenuWrapper.classList.toggle("active");
document.body.classList.toggle("menu-open");
});
}
// Close menu when a link is clicked
navLinks.forEach((link) => {
link.addEventListener("click", () => {
if (navMenuWrapper.classList.contains("active")) {
menuToggle.classList.remove("active");
navMenuWrapper.classList.remove("active");
document.body.classList.remove("menu-open");
}
});
});
};
/**
* Changes header style on scroll.
*/
const initHeaderScroll = () => {
const header = document.querySelector(".main-header");
if (!header) return;
window.addEventListener("scroll", () => {
if (window.scrollY > 50) {
header.classList.add("scrolled");
} else {
header.classList.remove("scrolled");
}
});
};
/**
* Reveals elements on scroll using IntersectionObserver.
*/
const initScrollReveal = () => {
const revealItems = document.querySelectorAll(".reveal-item");
if (revealItems.length === 0) return;
const revealObserver = new IntersectionObserver(
(entries, observer) => {
entries.forEach((entry) => {
if (entry.isIntersecting) {
entry.target.classList.add("visible");
observer.unobserve(entry.target);
}
});
},
{ threshold: 0.1 }
);
revealItems.forEach((item) => {
revealObserver.observe(item);
});
};
/**
* Highlights the active navigation link based on scroll position.
*/
const initActiveNavHighlighting = () => {
const sections = document.querySelectorAll(".scroll-section");
const navLinks = document.querySelectorAll(".nav-link");
if (sections.length === 0 || navLinks.length === 0) return;
const highlightObserver = new IntersectionObserver(
(entries) => {
entries.forEach((entry) => {
if (entry.isIntersecting) {
navLinks.forEach((link) => {
link.classList.remove("active-link");
if (
link
.getAttribute("href")
.includes(entry.target.id)
) {
link.classList.add("active-link");
}
});
}
});
},
{ rootMargin: "-40% 0px -60% 0px" }
); // Highlights when section is in the middle of the viewport
sections.forEach((section) => {
highlightObserver.observe(section);
});
};
/**
* Handles the interactive features showcase section.
*/
const initFeatureShowcase = () => {
const featureItems = document.querySelectorAll(".feature-item");
const previewItems = document.querySelectorAll(".feature-preview-item");
if (featureItems.length === 0) return;
featureItems.forEach((button) => {
button.addEventListener("click", () => {
const featureToShow = button.dataset.feature;
// Update active state on buttons
featureItems.forEach((item) => item.classList.remove("active"));
button.classList.add("active");
// Show the corresponding preview
previewItems.forEach((preview) => {
if (preview.id === `feature-preview-${featureToShow}`) {
preview.classList.add("visible");
} else {
preview.classList.remove("visible");
}
});
});
});
};
const initPricingToggle = () => {
const switchInput = document.getElementById("pricing-switch");
if (!switchInput) return;
const pricingCards = document.querySelectorAll(".plan-price");
switchInput.addEventListener("change", () => {
const isYearly = switchInput.checked;
pricingCards.forEach((card) => {
const priceValueEl = card.querySelector(".price-value");
if (!priceValueEl) return; // Skip the 'Custom' card
const monthlyPrice = card.dataset.monthly;
const yearlyPrice = card.dataset.yearly;
// Add a subtle fade-out effect
priceValueEl.style.opacity = "0";
setTimeout(() => {
priceValueEl.textContent = isYearly
? yearlyPrice
: monthlyPrice;
// Fade back in
priceValueEl.style.opacity = "1";
}, 150);
});
});
};
// Initialize all functionalities
initHeroParallax();
initHero3DParallax();
initMobileNav();
initHeaderScroll();
initScrollReveal();
initActiveNavHighlighting();
// Add this new function call
initFeatureShowcase();
initPricingToggle();
});