Scroll To Top
A floating action button that appears in the bottom-right corner once the user has scrolled past a threshold. Clicking it scrolls smoothly back to the top of the page.
Import
import { ScrollToTop } from "@phpcreation/frontend-components-react-nextjs-bundle/components/ScrollToTop";Props
| Prop | Type | Required | Default | Description |
|---|---|---|---|---|
threshold | number | — | 300 | Pixels scrolled before the button appears |
className | string | — | — | Additional CSS classes |
smooth | boolean | — | true | Use smooth scroll behavior |
queryStringSupport | boolean | — | true | Also trigger scroll when ?scrollTo=top is in the URL |
Usage
import { ScrollToTop } from "@phpcreation/frontend-components-react-nextjs-bundle/components/ScrollToTop";
// Place at the root layout level
export default function Layout({ children }) {
return (
<>
{children}
<ScrollToTop />
</>
);
}
// Custom threshold and no smooth scroll
<ScrollToTop threshold={500} smooth={false} />With queryStringSupport={true}, navigating to any URL with ?scrollTo=top will automatically trigger the scroll-to-top action. Useful for “back to top” links in emails or external pages.
Related
Last updated on