Below is a cleaner (and much closer-to-Apple) version that never “jumps under” your content.
Only ONE image is used – it’s pinned with position: sticky, smoothly shrinks until it is
≈ 1000 × 500 px, then simply scrolls away with the rest of the page.
When you scroll back up, the whole thing plays in reverse.
Copy-paste and you’re ready to go👇
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Parallax ‑ Apple-style Shrink</title>
<style>
/* ========== RESET ========== */
*,*::before,*::after{margin:0;padding:0;box-sizing:border-box;}
body{font-family:sans-serif;line-height:1.55;}
/* ========== HERO SECTION ========== */
.hero{
/* 150vh gives us ~ one extra viewport height to do the animation */
height:150vh;
}
.hero__sticky{
position:sticky; /* the magic: stays fixed until section is out of view */
top:0;
height:100vh; /* equal viewport height while pinned */
display:flex;
align-items:center;
justify-content:center;
pointer-events:none; /* so mouse-wheel keeps scrolling */
}
.hero__img{
width:100vw; /* full bleed at start */
height:auto; /* maintain aspect ratio */
object-fit:cover;
transform-origin:center center;
will-change:transform;
transition:transform .1s linear; /* small help for lower fps */
}
/* ========== CONTENT ========== */
.content{
padding:8rem clamp(1rem,4vw,4rem);
background:#fff;
}
.content h2{margin-bottom:.5em;font-size:clamp(2rem,5vw,3rem);}
.content p{max-width:60ch;margin-bottom:1.5em;color:#555;}
</style>
</head>
<body>
<!-- ---------------- HERO ---------------- -->
<section class="hero" id="hero">
<div class="hero__sticky">
<img src="https://images.unsplash.com/photo-1506905925346-21bda4d32df4?auto=format&fit=crop&w=2070&q=80"
alt="Hero" class="hero__img" id="heroImg">
</div>
</section>
<!-- -------------- REGULAR PAGE ------------ -->
<section class="content">
<h2>Welcome to our website</h2>
<p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Tempora, repellat.</p>
<p>Lorem ipsum dolor sit, amet consectetur adipisicing elit. Sequi quibusdam modi
ipsam nihil voluptate impedit, ipsa magni. Reiciendis, velit dolores.</p>
<h2>More Stuff</h2>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Fugit, maxime? Quas
hic modi excepturi recusandae facere sequi ipsum nulla.</p>
<p>Scroll back up ↕️ to see the reverse animation.</p>
</section>
<script>
/*
* Apple-style shrink-on-scroll
* ----------------------------
* We measure how far the hero section has been scrolled.
* 0 => image full-screen
* 1 => image target size (~1000×500) and then just scrolls away
*/
const hero = document.getElementById('hero');
const heroImg = document.getElementById('heroImg');
const TARGET_W = 1000; // px ---- desired final width
const TARGET_H = 500; // px ---- " height
function clamp(min, val, max){ return Math.min(Math.max(val,min), max); }
function update(){
const rect = hero.getBoundingClientRect();
const totalScroll = hero.offsetHeight - window.innerHeight; // how much room we have
const scrolled = clamp(0, -rect.top, totalScroll); // positive value while sticky
const progress = scrolled / totalScroll; // 0 → 1
/* ----- compute scale so width goes 100vw → TARGET_W ----- */
const fullW = window.innerWidth;
const targetScale = Math.min(TARGET_W / fullW, 1); // don’t upscale on small screens
const scale = 1 - (1 - targetScale) * progress;
/* ----- optional vertical shift (Apple slides it up a bit) -----
const translateY = -40 * progress // pixels
heroImg.style.transform = `translateY(${translateY}px) scale(${scale})`;
*/
heroImg.style.transform = `scale(${scale})`;
requestAnimationFrame(update); // we keep it ultra-smooth
}
update(); // kick off loop
</script>
</body>
</html>
What changed & why it fixes the “jump”
-
position: sticky
• Keeps the image pinned while you’re inside the hero section – no display:none/ block flip-flop.
• Once the hero section scrolls out, it naturally scrolls away like any normal element (so the image sits right above “Welcome to our website”).
-
Only one <img> element
• No duplicate/hidden copy means no flicker or sudden vanishing.
-
Continuous requestAnimationFrame loop
• Guarantees ultra-smooth updates at the monitor’s refresh rate.
-
Scalable down to 1000×500
• The JS calculates a scale factor so the image width ends at ≈ 1000 px on large screens.
• On small devices where 100vw is already < 1000 px we simply keep it at full width (no up-scaling).
Feel free to tweak:
• Change TARGET_W / TARGET_H to any size you prefer.
• Add extra transforms (e.g. small upward translateY, subtle opacity fade, border-radius) to mimic Apple’s fine details.
Enjoy the slick parallax hero!