This is a great performance optimization exercise. Let me create a complete, production-ready landing page with:
Let me create a full, working example with multiple sections showing different parallax effects.
html Copy code
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Parallax Landing - 60fps Optimized</title>
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
html {
scroll-behavior: auto; /* Disable smooth scroll for performance */
}
body {
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
overflow-x: hidden;
background: #000;
color: #fff;
}
/* ============================================
HERO SECTION
============================================ */
.hero {
position: relative;
height: 100vh;
overflow: hidden;
display: flex;
align-items: center;
justify-content: center;
}
.hero-bg {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
will-change: transform;
transform: translate3d(0, 0, 0);
}
.hero-content {
position: relative;
z-index: 10;
text-align: center;
max-width: 600px;
padding: 20px;
}
.hero h1 {
font-size: clamp(2rem, 8vw, 4rem);
margin-bottom: 20px;
will-change: opacity, transform;
transform: translate3d(0, 0, 0);
}
.hero p {
font-size: 1.2rem;
margin-bottom: 40px;
opacity: 0.9;
will-change: opacity, transform;
transform: translate3d(0, 0, 0);
}
.cta-button {
display: inline-block;
padding: 12px 40px;
background: rgba(255, 255, 255, 0.2);
border: 2px solid #fff;
border-radius: 50px;
color: #fff;
text-decoration: none;
font-size: 1rem;
cursor: pointer;
transition: background 0.3s ease;
will-change: background;
}
.cta-button:hover {
background: rgba(255, 255, 255, 0.3);
}
/* ============================================
PARALLAX SECTION BASE
============================================ */
section {
position: relative;
padding: 100px 20px;
min-height: 100vh;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
}
section h2 {
font-size: clamp(2rem, 5vw, 3rem);
margin-bottom: 60px;
text-align: center;
will-change: opacity, transform;
transform: translate3d(0, 0, 0);
}
/* ============================================
FEATURES SECTION
============================================ */
.features {
background: #111;
position: relative;
}
.features-grid {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
gap: 40px;
max-width: 1200px;
width: 100%;
margin-top: 40px;
}
.feature-card {
padding: 40px;
background: rgba(102, 126, 234, 0.1);
border-radius: 12px;
border: 1px solid rgba(102, 126, 234, 0.3);
will-change: transform, opacity;
transform: translate3d(0, 0, 0);
}
.feature-card h3 {
margin-bottom: 15px;
font-size: 1.3rem;
}
.feature-card p {
line-height: 1.6;
opacity: 0.8;
}
/* ============================================
GALLERY SECTION
============================================ */
.gallery {
background: #1a1a1a;
}
.gallery-container {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
gap: 30px;
max-width: 1200px;
width: 100%;
margin-top: 40px;
}
.gallery-item {
position: relative;
aspect-ratio: 1;
overflow: hidden;
border-radius: 8px;
background: rgba(102, 126, 234, 0.2);
will-change: transform, opacity;
transform: translate3d(0, 0, 0);
}
.gallery-item::before {
content: '';
position: absolute;
inset: 0;
background: linear-gradient(135deg, rgba(102, 126, 234, 0.3), rgba(118, 75, 162, 0.3));
}
/* ============================================
STATS SECTION
============================================ */
.stats {
background: linear-gradient(180deg, #1a1a1a 0%, #111 100%);
}
.stats-grid {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
gap: 40px;
max-width: 1000px;
width: 100%;
margin-top: 40px;
}
.stat-item {
text-align: center;
will-change: transform, opacity;
transform: translate3d(0, 0, 0);
}
.stat-number {
font-size: clamp(2rem, 5vw, 3.5rem);
font-weight: bold;
background: linear-gradient(135deg, #667eea, #764ba2);
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
background-clip: text;
margin-bottom: 10px;
}
.stat-label {
font-size: 1.1rem;
opacity: 0.8;
}
/* ============================================
TESTIMONIALS SECTION
============================================ */
.testimonials {
background: #0a0a0a;
}
.testimonial-container {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
gap: 30px;
max-width: 1200px;
width: 100%;
margin-top: 40px;
}
.testimonial {
padding: 30px;
background: rgba(102, 126, 234, 0.08);
border-left: 4px solid #667eea;
border-radius: 4px;
will-change: transform, opacity;
transform: translate3d(0, 0, 0);
}
.testimonial-text {
font-size: 1rem;
line-height: 1.7;
margin-bottom: 20px;
font-style: italic;
}
.testimonial-author {
font-weight: 600;
opacity: 0.8;
}
/* ============================================
FOOTER
============================================ */
footer {
padding: 40px 20px;
text-align: center;
background: #000;
border-top: 1px solid rgba(255, 255, 255, 0.1);
opacity: 0.8;
}
/* ============================================
SCROLLBAR (Optional)
============================================ */
::-webkit-scrollbar {
width: 8px;
}
::-webkit-scrollbar-track {
background: #111;
}
::-webkit-scrollbar-thumb {
background: #667eea;
border-radius: 4px;
}
::-webkit-scrollbar-thumb:hover {
background: #764ba2;
}
/* ============================================
PERFORMANCE: Reduce motion for accessibility
============================================ */
@media (prefers-reduced-motion: reduce) {
* {
animation-duration: 0.01ms !important;
animation-iteration-count: 1 !important;
transition-duration: 0.01ms !important;
scroll-behavior: auto !important;
}
.hero-bg,
.hero h1,
.hero p,
section h2,
.feature-card,
.gallery-item,
.stat-item,
.testimonial {
will-change: auto !important;
}
}
</style>
</head>
<body>
<!-- Hero Section -->
<section class="hero">
<div class="hero-bg"></div>
<div class="hero-content">
<h1 data-parallax="0.5">Welcome to Smooth 60fps</h1>
<p data-parallax="0.3">Experience buttery-smooth parallax effects optimized for high performance</p>
<a href="#features" class="cta-button">Explore</a>
</div>
</section>
<!-- Features Section -->
<section class="features" id="features">
<h2 data-parallax="0.4">Why It's Fast</h2>
<div class="features-grid">
<div class="feature-card" data-parallax="0.2">
<h3>GPU Accelerated</h3>
<p>Only transform3d and opacity properties are animated, ensuring hardware acceleration on all devices.</p>
</div>
<div class="feature-card" data-parallax="0.25">
<h3>60fps Guaranteed</h3>
<p>RequestAnimationFrame keeps animations in sync with screen refresh rates for smooth motion.</p>
</div>
<div class="feature-card" data-parallax="0.3">
<h3>Passive Listeners</h3>
<p>Event listeners use passive mode to prevent blocking the main thread during scrolling.</p>
</div>
</div>
</section>
<!-- Gallery Section -->
<section class="gallery" id="gallery">
<h2 data-parallax="0.35">Gallery</h2>
<div class="gallery-container">
<div class="gallery-item" data-parallax="0.15"></div>
<div class="gallery-item" data-parallax="0.2"></div>
<div class="gallery-item" data-parallax="0.25"></div>
<div class="gallery-item" data-parallax="0.3"></div>
<div class="gallery-item" data-parallax="0.35"></div>
<div class="gallery-item" data-parallax="0.4"></div>
</div>
</section>
<!-- Stats Section -->
<section class="stats">
<h2 data-parallax="0.4">By The Numbers</h2>
<div class="stats-grid">
<div class="stat-item" data-parallax="0.2">
<div class="stat-number">60</div>
<div class="stat-label">FPS Performance</div>
</div>
<div class="stat-item" data-parallax="0.25">
<div class="stat-number">0ms</div>
<div class="stat-label">Layout Shifts</div>
</div>
<div class="stat-item" data-parallax="0.3">
<div class="stat-number">100%</div>
<div class="stat-label">GPU Accelerated</div>
</div>
<div class="stat-item" data-parallax="0.35">
<div class="stat-number">∞</div>
<div class="stat-label">Smooth Scrolling</div>
</div>
</div>
</section>
<!-- Testimonials Section -->
<section class="testimonials">
<h2 data-parallax="0.4">What Users Say</h2>
<div class="testimonial-container">
<div class="testimonial" data-parallax="0.2">
<p class="testimonial-text">"The smoothness is incredible. No jank, no lag, just pure performance."</p>
<p class="testimonial-author">— Developer</p>
</div>
<div class="testimonial" data-parallax="0.25">
<p class="testimonial-text">"Finally, a parallax implementation that doesn't kill my phone's battery."</p>
<p class="testimonial-author">— Mobile User</p>
</div>
<div class="testimonial" data-parallax="0.3">
<p class="testimonial-text">"The attention to performance details is outstanding. Highly recommend."</p>
<p class="testimonial-author">— Web Performance Expert</p>
</div>
</div>
</section>
<!-- Footer -->
<footer>
<p>© 2024 Parallax Landing. Built with performance in mind.</p>
</footer>
<script>
/**
* High-Performance Parallax Engine
* - Uses only transform translate3d and opacity
* - Passive event listeners
* - RequestAnimationFrame loop
* - Minimal repaints and reflows
*/
class ParallaxEngine {
constructor() {
this.elements = [];
this.scrollY = 0;
this.targetScrollY = 0;
this.isAnimating = false;
this.viewportHeight = window.innerHeight;
this.init();
}
/**
* Initialize the parallax engine
*/
init() {
this.collectElements();
this.setupListeners();
this.startAnimationLoop();
}
/**
* Collect all elements with parallax data attribute
*/
collectElements() {
const parallaxElements = document.querySelectorAll('[data-parallax]');
parallaxElements.forEach(element => {
const speed = parseFloat(element.getAttribute('data-parallax'));
// Calculate initial position
const rect = element.getBoundingClientRect();
const absoluteTop = rect.top + window.scrollY;
this.elements.push({
element,
speed,
absoluteTop,
elementHeight: element.offsetHeight,
initialTranslate: 0,
});
});
console.log(`✓ Parallax engine loaded ${this.elements.length} elements`);
}
/**
* Setup event listeners (passive mode)
*/
setupListeners() {
// Passive scroll listener
window.addEventListener('scroll', () => {
this.targetScrollY = window.scrollY;
}, { passive: true });
// Passive resize listener
window.addEventListener('resize', () => {
this.viewportHeight = window.innerHeight;
}, { passive: true });
// Passive wheel listener
window.addEventListener('wheel', () => {
// Passive - no preventDefault
}, { passive: true });
// Passive touch listeners
window.addEventListener('touchmove', () => {
// Passive - no preventDefault
}, { passive: true });
}
/**
* Main animation loop using requestAnimationFrame
*/
startAnimationLoop() {
const loop = () => {
this.updateParallax();
requestAnimationFrame(loop);
};
requestAnimationFrame(loop);
}
/**
* Update parallax positions efficiently
* Batch all DOM reads before writes
*/
updateParallax() {
// Early exit if scroll position hasn't changed
if (this.scrollY === this.targetScrollY) {
return;
}
this.scrollY = this.targetScrollY;
// Batch update all elements
this.elements.forEach(item => {
this.updateElement(item);
});
}
/**
* Update individual element transform
* Only modifies transform and opacity
*/
updateElement(item) {
const { element, speed, absoluteTop, elementHeight } = item;
// Calculate viewport-relative position
const elementCenterY = absoluteTop + elementHeight / 2;
const viewportCenter = this.scrollY + this.viewportHeight / 2;
const distance = viewportCenter - elementCenterY;
// Calculate parallax offset
const offset = distance * speed;
// Calculate opacity based on viewport visibility
const distanceFromViewport = Math.abs(distance);
const maxDistance = this.viewportHeight / 2 + elementHeight / 2;
const opacity = Math.max(0, 1 - distanceFromViewport / maxDistance * 0.5);
// Apply hardware-accelerated transform
// Only use translate3d and opacity
element.style.transform = `translate3d(0, ${offset}px, 0)`;
// Only update opacity if visibility changes significantly
if (opacity < 0.95 || opacity > 0.05) {
element.style.opacity = Math.max(0, Math.min(1, opacity + 0.3));
} else {
element.style.opacity = '1';
}
}
/**
* Public method to refresh element positions
* Call after DOM changes
*/
refresh() {
this.elements = [];
this.collectElements();
}
}
/**
* Performance Monitoring (Optional)
* Remove in production
*/
class PerformanceMonitor {
constructor() {
this.frameCount = 0;
this.lastTime = performance.now();
this.fps = 0;
this.maxFrameTime = 0;
this.startMonitoring();
}
startMonitoring() {
const monitor = () => {
const now = performance.now();
const frameTime = now - this.lastTime;
this.frameCount++;
this.maxFrameTime = Math.max(this.maxFrameTime, frameTime);
if (frameTime >= 1000) {
this.fps = this.frameCount;
this.frameCount = 0;
this.lastTime = now;
this.logPerformance();
}
requestAnimationFrame(monitor);
};
requestAnimationFrame(monitor);
}
logPerformance() {
// Uncomment to see FPS in console
// console.log(`FPS: ${this.fps} | Max Frame: ${this.maxFrameTime.toFixed(2)}ms`);
}
}
/**
* Initialize when DOM is ready
*/
document.addEventListener('DOMContentLoaded', () => {
const engine = new ParallaxEngine();
// const monitor = new PerformanceMonitor(); // Uncomment for debugging
// Expose refresh method for dynamic content
window.refreshParallax = () => engine.refresh();
// Log initialization
console.log('✓ Parallax landing page initialized');
console.log('✓ Scroll performance optimized for 60fps');
console.log('✓ All animations use GPU acceleration');
});
/**
* Cleanup on page unload
*/
window.addEventListener('beforeunload', () => {
document.querySelectorAll('[data-parallax]').forEach(el => {
el.style.transform = '';
el.style.opacity = '';
});
});
</script>
</body>
</html>