react-snap-page
v1.0.0
Published
Fullscreen snap scrolling for React
Downloads
113
Maintainers
Readme
react-snap-page
Lightweight fullscreen snap scrolling for React & Next.js.
Smooth section-based scrolling inspired by fullpage experiences without heavy dependencies.
Features
- Fullscreen section snapping
- Smooth scrolling animation
- Mouse wheel navigation
- Touch swipe support
- Keyboard navigation
- React 18+ support
- Next.js compatible
- TypeScript support
- Lightweight
- No external dependencies
- ESM + CommonJS support
Installation
npm install react-snap-pageor
yarn add react-snap-pageor
pnpm add react-snap-pageImport CSS
Import the default styles once in your app.
Next.js App Router
import "react-snap-page/dist/index.css";Usually inside:
app/layout.tsxBasic Usage
"use client";
import { SnapPage, Section } from "react-snap-page";
import "react-snap-page/dist/index.css";
export default function Page() {
return (
<SnapPage>
<Section>
<div className="hero">
<h1>Hero Section</h1>
</div>
</Section>
<Section>
<div className="about">
<h1>About Section</h1>
</div>
</Section>
<Section>
<div className="projects">
<h1>Projects Section</h1>
</div>
</Section>
</SnapPage>
);
}Components
SnapPage
Main wrapper component.
Props
| Prop | Type | Default | Description |
| ----------- | --------- | ------- | ----------------------------------------- |
| duration | number | 1000 | Scroll animation duration in milliseconds |
| threshold | number | 80 | Wheel/touch sensitivity threshold |
| wheel | boolean | true | Enable mouse wheel scrolling |
| touch | boolean | true | Enable touch swipe scrolling |
| keyboard | boolean | true | Enable keyboard navigation |
Section
Fullscreen section component.
Props
| Prop | Type | Default | Description |
| ----------- | -------- | ------- | ---------------- |
| className | string | "" | Custom className |
Example With Props
"use client";
import { SnapPage, Section } from "react-snap-page";
import "react-snap-page/dist/index.css";
export default function HomePage() {
return (
<SnapPage
duration={1200}
threshold={60}
wheel={true}
touch={true}
keyboard={true}
>
<Section className="section-one">
<h1>Section One</h1>
</Section>
<Section className="section-two">
<h1>Section Two</h1>
</Section>
<Section className="section-three">
<h1>Section Three</h1>
</Section>
</SnapPage>
);
}Keyboard Controls
| Key | Action |
| ------------ | ---------------- |
| Arrow Down | Next section |
| Arrow Up | Previous section |
| Page Down | Next section |
| Page Up | Previous section |
Touch Support
Mobile touch gestures are supported automatically.
| Gesture | Action | | ---------- | ---------------- | | Swipe Up | Next section | | Swipe Down | Previous section |
Styling
Default styles are minimal.
You can fully customize sections using your own CSS, Tailwind, or any styling library.
Example:
.section {
display: flex;
align-items: center;
justify-content: center;
}Tailwind Example
<Section className="bg-black text-white flex items-center justify-center">
<h1 className="text-6xl font-bold">Hello World</h1>
</Section>Next.js Example
app/layout.tsx
import "react-snap-page/dist/index.css";
export default function RootLayout({
children,
}: {
children: React.ReactNode;
}) {
return (
<html lang="en">
<body>{children}</body>
</html>
);
}app/page.tsx
"use client";
import { SnapPage, Section } from "react-snap-page";
export default function Page() {
return (
<SnapPage>
<Section>
<h1>Hero</h1>
</Section>
<Section>
<h1>About</h1>
</Section>
<Section>
<h1>Projects</h1>
</Section>
</SnapPage>
);
}TypeScript Support
Built with TypeScript and includes full type definitions.
No additional typings required.
Browser Support
- Chrome
- Edge
- Firefox
- Safari
- Mobile browsers
Accessibility Notes
Keyboard navigation is enabled by default.
You can disable it:
<SnapPage keyboard={false}>Performance
- Uses
requestAnimationFrame - No heavy dependencies
- Small bundle size
- Optimized for smooth scrolling
Package Size
Approximate package size:
~3kbRoadmap
Planned features:
- Navigation dots
- URL hash sync
- Horizontal mode
- Parallax support
- Scroll callbacks
- Nested scroll support
- SSR hydration improvements
- Section animations
Contributing
Contributions are welcome.
Feel free to open issues or pull requests.
License
MIT License
