A full-page screenshot in a frame with fixed proportions. On hover it scrolls down, and if the pointer leaves halfway it goes back from where it stopped and noticeably faster. It is a server component with no JavaScript: a CSS transition on translate, and the frame is a size container, so the end offset is calc(100cqh - 100%) with no measuring. Keyboard focus starts the scroll too, and on touch screens a tap focuses the frame.
Browser Support
Sizes the screenshot frame.
Shapes the scroll animation.
Preview
Hover the frame, or tap it on a phone.
Installation
Usage
import { HoverScrollScreenshot } from "@/components/ui/hover-scroll-screenshot"
export default function Example() {
return (
<HoverScrollScreenshot
src="/screenshots/landing-full.png"
alt="Landing page"
className="max-w-md"
/>
)
}Examples
Motion variants
Three ways to move. The duration is shared, only the path changes.
<HoverScrollScreenshot src={src} alt="Landing" variant="glide" />
<HoverScrollScreenshot src={src} alt="Landing" variant="bounce" />
<HoverScrollScreenshot src={src} alt="Landing" variant="zoom" />Speed and duration
duration is the time from top to bottom. CSS cannot read the image height, so it does not adapt to the page length: give long screenshots a longer duration.
<HoverScrollScreenshot src={src} alt="Landing" duration={10000} />
<HoverScrollScreenshot src={src} alt="Landing" duration={3000} returnSpeedup={4} />Inside a card
Override the frame with className: aspect ratio, border, radius.
Studio landing page
Marketing site, 9 sections
<div className="overflow-hidden rounded-xl border bg-card">
<HoverScrollScreenshot
src={src}
alt="Studio landing page"
variant="zoom"
className="aspect-[16/10] rounded-none border-0 border-b"
/>
<div className="p-4">
<p className="font-medium">Studio landing page</p>
</div>
</div>Props
| Prop | Type | Default | Description |
|---|---|---|---|
| src | string | - | URL of the tall screenshot |
| alt | string | - | Image description, also the accessible name of the frame |
| variant | "glide" | "bounce" | "zoom" | "glide" | Motion style |
| duration | number | 6000 | Scroll time from top to bottom, ms |
| returnSpeedup | number | 6 | How many times faster the way back is |
| --hss-easing | timing-function | cubic-bezier(.45,0,.15,1) | CSS variable, set via style: easing of the way in. Slow start, long deceleration at the edge |
| --hss-easing-out | timing-function | cubic-bezier(.3,0,.1,1) | CSS variable, set via style: easing of the way back, softens the stop at the top |
| imageClassName | string | - | Classes for the img element |
| className | string | - | Frame classes; the default ratio is aspect-[4/3] |
Features
- Resumes from the current point: an interrupted scroll reverses from the frame you see, without a jump
- No JavaScript: hover, focus and transitions do all the work
- Touch and keyboard: focus with Tab or a tap starts the scroll; moving focus away scrolls back
- Reduced motion: with prefers-reduced-motion the image stays still