antfu/img-auto-parallax
Media & DesignA drop-in web component that adds GPU-estimated depth and parallax to any photo on hover or device tilt.
What it does
img-auto-parallax is a web component that replaces a plain <img> with a photo that reacts to the pointer and to a phone's tilt. Depth is estimated on the device with WebGPU, using a bundled model, and the result is a parallax effect rather than a static picture. If the browser lacks WebGPU, the component falls back to the ordinary image. It targets web developers building photo galleries or landing pages who want depth without a server-side pipeline.
Quick start
Install the package with pnpm:
pnpm add img-auto-parallax
Import the custom element definition once, then use the element anywhere in the page:
import 'img-auto-parallax/define'
<img-auto-parallax src="/photo.jpg" alt="A mountain lake"></img-auto-parallax>
Serve the page over HTTPS or localhost so WebGPU is available. On iOS Safari, device motion requires permission tied to a user gesture; tapping the image triggers the prompt, or you can wire it yourself with getGyroPermission() and requestGyroPermission() from a click handler. The project's playground shows the effect next to a plain image, and there is an intro video.
Constraints
- WebGPU and motion events only work in secure contexts; over plain HTTP the image stays static.
- On iOS Safari, gyro access is gated behind a user gesture.
- Depth estimation runs locally but depends on the bundled Apache-2.0 model (model notice); larger photos mean more GPU work.
- The library is MIT-licensed (license), and the depth engine is built on Vercel's vgpu.
HotRepo's take
The repository has one recorded appearance on HotRepo's new-project board for TypeScript on 2026-12-01, gaining 105 stars in a window of roughly 20 hours. That is a single snapshot, so it supports the fact of a fast opening but not a durability claim. The appeal is narrow and clear: a one-line web component that hides the depth-estimation machinery behind a familiar <img>-style tag, with a graceful fallback for unsupported browsers.
Written by AI from the project's public information and HotRepo's records, updated . The project's own docs are the source of truth.