Image Parallax
Pictures drift behind their frames, adding depth to every scroll.
Settings
What it does
Image Parallax is an image animation ready for your AI assistant, React or plain JavaScript, with no dependencies. Also called parallax or scroll parallax.
While the page scrolls, the image inside a frame slides a little slower than everything around it, as if seen through a window. Its edges never show, the work stops offscreen, and reduced motion keeps the picture still.
Documentation
One copy gives an assistant everything it needs: the complete code, every option and every pitfall. Paste it in Claude, Cursor or ChatGPT and say where the effect goes; it adapts the integration to your stack, not the code.
Copy the prompt
Ask for it
For instance: Add this image parallax effect to the hero of my home page.What it sends# Foundry44 · Image Parallax Image moves slower than its frame while scrolling. Add this component to my project. Pick the setup below that matches my project and follow only that one. When it uses the code at the end, keep its logic as written (it is self-contained, with no dependencies) and adapt only the integration: JavaScript instead of TypeScript if the project has none, file names, imports, how it starts. ## Markup it expects The element marked `data-f44="image-parallax"`, with this structure inside. Texts, images and the number of items are the demo's: use mine. The `data-f44-*` attributes set options for the ready-made script only; with the code, pass the same options to `imageParallax()` or as props. ```html <div data-f44="image-parallax" data-f44-speed="0.12"> <img src="image-1.jpg" alt="Cliffs over the sea at golden hour"> </div> ``` ## Options | Option | Attribute | Type | Default | Description | |---|---|---|---|---| | `speed` | `data-f44-speed` | `number` | `0.1` | How far the image drifts, as a fraction of the frame size on each side. Negative drifts the other way. | | `smoothing` | `data-f44-smoothing` | `number` | `0.2` | How closely the image follows the scroll each frame, 0–1. 1 is locked to it, lower glides behind. | | `axis` | `data-f44-axis` | `"x" | "y"` | `y` | Drift direction: "y" moves the image vertically, "x" sideways while the page scrolls down. | ## Setup - **Plain HTML, no build step**: don't paste the code below. Load the ready-made script once, at the end of `<body>`: `<script src="https://foundry44.dev/demos/image-parallax/image-parallax.js" defer></script>` (or download that file and serve it with the page). It starts itself on every `data-f44="image-parallax"` element and reads the `data-f44-*` attributes above. - **React / Next.js with shadcn/ui** (the project has a `components.json`; otherwise, see the next line): `npx shadcn@latest add https://foundry44.dev/r/image-parallax.json` writes `lib/image-parallax-core.ts` and `components/ui/image-parallax.tsx`, then use `<ImageParallax />` with the options as props. - **React / Next.js from npm** (no shadcn/ui, or the user prefers a package): `npm install @foundry44/react` (or the project's package manager), then `import { ImageParallax } from "@foundry44/react"` with the options as props. With a bundler and no React: `@foundry44/core`, then `import { imageParallax } from "@foundry44/core/image-parallax"`. - **React / Next.js by hand**: save the code below as `lib/image-parallax-core.ts` and import it from there (`@/lib/image-parallax-core` where that alias exists). Don't name it `image-parallax.ts` next to a `ImageParallax.tsx`: on macOS and Windows the two names collide. In a component marked `"use client"`, call `imageParallax(ref.current, options)` in a `useEffect` and return `instance.destroy` as its cleanup; call `instance.update(options)` when options change. - **Any other stack**: create on mount with `imageParallax(element, options)`, `update(options)` when they change, `destroy()` on unmount. Only the ready-made script finds `data-f44` elements and starts them by itself. Pasted code does not: call `imageParallax(element)` on each element. ## Pitfalls - Respects prefers-reduced-motion: keep that behaviour. - The image must be the element's first child: the element is the frame and gets `overflow: hidden`. - The image is enlarged by twice `speed` to hide its edges (1.2× by default): use a source with enough resolution. - Size the image to fill the frame, e.g. `width: 100%; height: 100%; object-fit: cover`. - With reduced motion the image stays still, at its normal size. ## Code: `image-parallax-core.ts` ```ts // Copyright (c) 2026 Foundry44 · MIT License (SPDX-License-Identifier: MIT) /** * Foundry44 — image-parallax * The image inside a frame drifts more slowly than the page while you scroll, * so the frame seems to be a window onto something further away. The image is * enlarged just enough that its edges never show inside the frame. * * Self-contained: no imports, so this file can be copied as-is. */ export interface ImageParallaxOptions { /** How far the image drifts, as a fraction of the frame size on each side. Negative drifts the other way. @range -0.5 0.5 0.01 */ speed?: number; /** How closely the image follows the scroll each frame, 0–1. 1 is locked to it, lower glides behind. @range 0.02 1 0.01 */ smoothing?: number; /** Drift direction: "y" moves the image vertically, "x" sideways while the page scrolls down. */ axis?: "x" | "y"; } export interface ImageParallaxInstance { update(options: ImageParallaxOptions): void; destroy(): void; } export const imageParallaxDefaults: Required<ImageParallaxOptions> = { speed: 0.1, smoothing: 0.2, axis: "y", }; const REST = 0.05; export function imageParallax(el: HTMLElement, options: ImageParallaxOptions = {}): ImageParallaxInstance { let opts = { ...imageParallaxDefaults, ...options }; const noop: ImageParallaxInstance = { update() {}, destroy() {} }; if (typeof window === "undefined") return noop; // The effect is pure movement: with reduced motion the image just stays still. if (window.matchMedia?.("(prefers-reduced-motion: reduce)").matches) return noop; const image = el.firstElementChild instanceof HTMLElement ? el.firstElementChild : null; if (!image) return noop; const original = { overflow: el.style.overflow, transform: image.style.transform, willChange: image.style.willChange, }; el.style.overflow = "hidden"; image.style.willChange = "transform"; let current = 0; let target = 0; let frame = 0; let observer: IntersectionObserver | null = null; // -1 when the frame's top meets the bottom of the viewport, 1 when its bottom meets the top. const measure = () => { const rect = el.getBoundingClientRect(); const viewport = window.innerHeight || 1; const travel = (viewport + rect.height) / 2 || 1; const progress = (viewport / 2 - (rect.top + rect.height / 2)) / travel; const size = opts.axis === "x" ? rect.width : rect.height; target = Math.min(Math.max(progress, -1), 1) * opts.speed * size; }; const render = () => { // Scaled from the center by twice the drift, so neither edge ever comes into the frame. const scale = 1 + 2 * Math.abs(opts.speed); const offset = opts.axis === "x" ? `${current}px, 0` : `0, ${current}px`; image.style.transform = `translate3d(${offset}, 0) scale(${scale})`; }; const tick = () => { const amount = Math.min(Math.max(opts.smoothing, 0.01), 1); current += (target - current) * amount; if (Math.abs(target - current) < REST) { current = target; render(); frame = 0; return; } render(); frame = requestAnimationFrame(tick); }; const onScroll = () => { measure(); if (!frame) frame = requestAnimationFrame(tick); }; const listen = () => { window.addEventListener("scroll", onScroll, { passive: true }); window.addEventListener("resize", onScroll, { passive: true }); onScroll(); }; const unlisten = () => { window.removeEventListener("scroll", onScroll); window.removeEventListener("resize", onScroll); if (frame) cancelAnimationFrame(frame); frame = 0; }; // Start at the right offset, so the first scroll doesn't make the image jump. measure(); current = target; render(); if (typeof IntersectionObserver === "undefined") { listen(); } else { // Scroll work only while the frame is on screen. observer = new IntersectionObserver((entries) => { for (const entry of entries) { if (entry.isIntersecting) listen(); else unlisten(); } }); observer.observe(el); } return { update(next) { opts = { ...opts, ...next }; measure(); current = target; render(); }, destroy() { observer?.disconnect(); unlisten(); el.style.overflow = original.overflow; image.style.transform = original.transform; image.style.willChange = original.willChange; }, }; } ```
Two files that become yours: the engine, written without React, and a thin component around it. No package to install. The component is marked use client, so it sits inside a server component as it is.
Add it with the shadcn CLI
In a project set up for shadcn/ui, one command writes both files. Without it, copy them by hand in the two steps below.npx shadcn@latest add https://foundry44.dev/r/image-parallax.json
Or add the engine by hand
Save it aslib/image-parallax-core.ts. It has no dependencies and does nothing on the server.And the component
Save it ascomponents/ui/image-parallax.tsx. It creates the effect on mount, passes every prop change to it live, and cleans up on unmount.// Copyright (c) 2026 Foundry44 · MIT License (SPDX-License-Identifier: MIT) // Generated by scripts/generate.mjs. Do not edit: change the core component instead. "use client"; import { useEffect, useRef, type ComponentPropsWithoutRef } from "react"; import { imageParallax, type ImageParallaxOptions, type ImageParallaxInstance } from "@/lib/image-parallax-core"; export interface ImageParallaxProps extends ImageParallaxOptions, Omit<ComponentPropsWithoutRef<"div">, keyof ImageParallaxOptions> {} export function ImageParallax({ speed, smoothing, axis, style, ...props }: ImageParallaxProps) { const ref = useRef<HTMLElementTagNameMap["div"]>(null); const instance = useRef<ImageParallaxInstance | null>(null); useEffect(() => { if (!ref.current) return; instance.current = imageParallax(ref.current); return () => { instance.current?.destroy(); instance.current = null; }; }, []); // Runs right after creation, then on every option change. useEffect(() => { instance.current?.update(definedOnly({ speed, smoothing, axis })); }, [speed, smoothing, axis]); return <div ref={ref} style={style} {...props} />; } function definedOnly<T extends object>(o: T): T { return Object.fromEntries(Object.entries(o).filter(([, v]) => v !== undefined)) as T; }
Or install the package
It is also on npm, in@foundry44/reactwith the other free components. Import it from there instead of@/components/ui.npm install @foundry44/react
import { ImageParallax } from "@foundry44/react";
Use it
Every prop is optional: with none, you get the effect as the preview shows it.import { ImageParallax } from "@/components/ui/image-parallax"; export function Example() { return ( <ImageParallax speed={0.1} smoothing={0.2} axis="y" > {/* your content */} </ImageParallax> ); }
PropsProp Default What it is speed 0.1 How far the image drifts, as a fraction of the frame size on each side. Negative drifts the other way. smoothing 0.2 How closely the image follows the scroll each frame, 0–1. 1 is locked to it, lower glides behind. axis y Drift direction: "y" moves the image vertically, "x" sideways while the page scrolls down. Avoid the pitfalls
- It follows
prefers-reduced-motion: under reduced motion the effect settles at once. - The image must be the element's first child: the element is the frame and gets
overflow: hidden. - The image is enlarged by twice
speedto hide its edges (1.2× by default): use a source with enough resolution. - Size the image to fill the frame, e.g.
width: 100%; height: 100%; object-fit: cover. - With reduced motion the image stays still, at its normal size.
- It follows
One file, readable, no dependencies and no build step. It sets itself up on every element marked data-f44="image-parallax", in plain HTML, WordPress, Framer embeds or any framework.
Load the script
Download it, put it next to your page and load it once, anywhere in the page.<script src="image-parallax.js" defer></script>
The file/*! * Foundry44 · Image Parallax — https://foundry44.dev/components/image-parallax * Image moves slower than its frame while scrolling. * Copyright (c) 2026 Foundry44 · MIT License (SPDX-License-Identifier: MIT) * * Usage: load this file, then add data-f44="image-parallax" to any element. * Optional attributes (defaults shown): * data-f44-speed="0.1" * data-f44-smoothing="0.2" * data-f44-axis="y" * Manual: const instance = Foundry44.imageParallax(element, { speed: 0.1, smoothing: 0.2, axis: "y" }); * instance.destroy(); * Re-scan the page after adding elements dynamically: Foundry44.init(); * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ (function () { "use strict"; /** * Foundry44 — image-parallax * The image inside a frame drifts more slowly than the page while you scroll, * so the frame seems to be a window onto something further away. The image is * enlarged just enough that its edges never show inside the frame. * * Self-contained: no imports, so this file can be copied as-is. */ const imageParallaxDefaults = { speed: 0.1, smoothing: 0.2, axis: "y", }; const REST = 0.05; function imageParallax(el, options = {}) { var _a; let opts = { ...imageParallaxDefaults, ...options }; const noop = { update() {}, destroy() {} }; if (typeof window === "undefined") return noop; // The effect is pure movement: with reduced motion the image just stays still. if ( (_a = window.matchMedia) === null || _a === void 0 ? void 0 : _a.call(window, "(prefers-reduced-motion: reduce)").matches ) return noop; const image = el.firstElementChild instanceof HTMLElement ? el.firstElementChild : null; if (!image) return noop; const original = { overflow: el.style.overflow, transform: image.style.transform, willChange: image.style.willChange, }; el.style.overflow = "hidden"; image.style.willChange = "transform"; let current = 0; let target = 0; let frame = 0; let observer = null; // -1 when the frame's top meets the bottom of the viewport, 1 when its bottom meets the top. const measure = () => { const rect = el.getBoundingClientRect(); const viewport = window.innerHeight || 1; const travel = (viewport + rect.height) / 2 || 1; const progress = (viewport / 2 - (rect.top + rect.height / 2)) / travel; const size = opts.axis === "x" ? rect.width : rect.height; target = Math.min(Math.max(progress, -1), 1) * opts.speed * size; }; const render = () => { // Scaled from the center by twice the drift, so neither edge ever comes into the frame. const scale = 1 + 2 * Math.abs(opts.speed); const offset = opts.axis === "x" ? `${current}px, 0` : `0, ${current}px`; image.style.transform = `translate3d(${offset}, 0) scale(${scale})`; }; const tick = () => { const amount = Math.min(Math.max(opts.smoothing, 0.01), 1); current += (target - current) * amount; if (Math.abs(target - current) < REST) { current = target; render(); frame = 0; return; } render(); frame = requestAnimationFrame(tick); }; const onScroll = () => { measure(); if (!frame) frame = requestAnimationFrame(tick); }; const listen = () => { window.addEventListener("scroll", onScroll, { passive: true }); window.addEventListener("resize", onScroll, { passive: true }); onScroll(); }; const unlisten = () => { window.removeEventListener("scroll", onScroll); window.removeEventListener("resize", onScroll); if (frame) cancelAnimationFrame(frame); frame = 0; }; // Start at the right offset, so the first scroll doesn't make the image jump. measure(); current = target; render(); if (typeof IntersectionObserver === "undefined") { listen(); } else { // Scroll work only while the frame is on screen. observer = new IntersectionObserver((entries) => { for (const entry of entries) { if (entry.isIntersecting) listen(); else unlisten(); } }); observer.observe(el); } return { update(next) { opts = { ...opts, ...next }; measure(); current = target; render(); }, destroy() { observer === null || observer === void 0 ? void 0 : observer.disconnect(); unlisten(); el.style.overflow = original.overflow; image.style.transform = original.transform; image.style.willChange = original.willChange; }, }; } function parse(value) { if (value === "true") return true; if (value === "false") return false; var n = Number(value); return value !== "" && !isNaN(n) ? n : value; } function init() { document.querySelectorAll('[data-f44="image-parallax"]').forEach(function (el) { if (el.__f44) return; var options = {}; [ ["speed", "data-f44-speed"], ["smoothing", "data-f44-smoothing"], ["axis", "data-f44-axis"], ].forEach(function (pair) { var value = el.getAttribute(pair[1]); if (value !== null) options[pair[0]] = parse(value); }); el.__f44 = imageParallax(el, options); }); } var Foundry44 = (window.Foundry44 = window.Foundry44 || {}); Foundry44.imageParallax = imageParallax; Foundry44._inits = Foundry44._inits || []; Foundry44._inits.push(init); Foundry44.init = function () { Foundry44._inits.forEach(function (fn) { fn(); }); }; if (document.readyState === "loading") document.addEventListener("DOMContentLoaded", init); else init(); })();
Mark your element
Adddata-f44="image-parallax". Each setting is an attribute on the same element, and an attribute always wins over the default.<div data-f44="image-parallax" data-f44-speed="0.1"> <!-- your content --> </div>
SettingsAttribute Default What it is data-f44-speed 0.1 How far the image drifts, as a fraction of the frame size on each side. Negative drifts the other way. data-f44-smoothing 0.2 How closely the image follows the scroll each frame, 0–1. 1 is locked to it, lower glides behind. data-f44-axis y Drift direction: "y" moves the image vertically, "x" sideways while the page scrolls down. Drive it from JavaScript
When the element arrives after the page has loaded, or when the settings come from your code.// an element without data-f44, or the script would set it up twice const element = document.querySelector(".my-element"); const instance = Foundry44.imageParallax(element, { speed: 0.1, smoothing: 0.2 }); instance.update({ speed: 0.1 }); // any option, live instance.destroy(); // listeners and observers gone, inline styles restored // elements added after the page loaded Foundry44.init();
Avoid the pitfalls
- It follows
prefers-reduced-motion: under reduced motion the effect settles at once. - The image must be the element's first child: the element is the frame and gets
overflow: hidden. - The image is enlarged by twice
speedto hide its edges (1.2× by default): use a source with enough resolution. - Size the image to fill the frame, e.g.
width: 100%; height: 100%; object-fit: cover. - With reduced motion the image stays still, at its normal size.
- It follows
For a site builder: Webflow, WordPress, Shopify, Framer, or any site that accepts HTML. One block carries the whole script; paste it, then mark an element.
Paste the embed
Paste it where your builder takes custom HTML: an embed or code block on the page, or the site's footer code to use the effect on every page.Mark the element
Give the element the attributedata-f44with the valueimage-parallax. Most builders have a field for custom attributes; otherwise, add it to the element's HTML.SettingsEvery setting is an attribute too, on the same element. Leave one out and the default applies.Attribute Default What it is data-f44-speed 0.1 How far the image drifts, as a fraction of the frame size on each side. Negative drifts the other way. data-f44-smoothing 0.2 How closely the image follows the scroll each frame, 0–1. 1 is locked to it, lower glides behind. data-f44-axis y Drift direction: "y" moves the image vertically, "x" sideways while the page scrolls down. Avoid the pitfalls
- It follows
prefers-reduced-motion: under reduced motion the effect settles at once. - The image must be the element's first child: the element is the frame and gets
overflow: hidden. - The image is enlarged by twice
speedto hide its edges (1.2× by default): use a source with enough resolution. - Size the image to fill the frame, e.g.
width: 100%; height: 100%; object-fit: cover. - With reduced motion the image stays still, at its normal size.
- It follows