AnimateOnScroll
An unstyled component that applies CSS animations to elements entering or leaving the viewport.
Build fully custom scroll-triggered animations with complete control over enter and leave transitions.
Scroll Down
Discover real-world design inspiration.
Featuring over 400,000 screens and 1,000 iOS, Android & Web apps.
basic-demo
Pre-styled Versions
Choose a pre-styled library to use AnimateOnScroll with ready-made designs.
For hook-based usage without components, see the Headless API.
Features#
- Applies
enterClassNamewhen the element scrolls into view andleaveClassNamewhen it scrolls out - Configurable Intersection Observer options:
root,rootMargin,threshold oncemode to trigger animation only on first viewport entry- Automatic cleanup of animation classes after
animationendandtransitionendevents
Usage#
import { AnimateOnScroll } from 'primereact/animateonscroll';<AnimateOnScroll enterClassName="" leaveClassName=""></AnimateOnScroll>Behavior#
Polymorphic Rendering#
Use as to change the rendered HTML element.
<AnimateOnScroll as="section" enterClassName="fade-in">
...
</AnimateOnScroll>Default element: div.
API#
AnimateOnScroll#
| Name | Type | Default |
|---|---|---|
ref | Ref<unknown> | — |
| The reference to the component instance. | ||
pIf | boolean | true |
| Whether the component should be rendered. | ||
style | CSSProperties | ((instance?: AnimateOnScrollInstance) => CSSProperties) | — |
| The style to apply to the component. | ||
className | string | ((instance?: AnimateOnScrollInstance) => string) | — |
| The class name to apply to the component. | ||
as | string | number | bigint | boolean | ComponentClass<any, any> | FunctionComponent<any> | ReactElement<unknown, string | JSXElementConstructor<any>> | Iterable<ReactNode, any, any> | ReactPortal | Promise<AwaitedReactNode> | — |
| The component type to render. | ||
asChild | boolean | false |
| Whether the component should be rendered as a child component. | ||
instance | AnimateOnScrollInstance | — |
| The instance to pass to the component. | ||
pt | SafeRecord<AnimateOnScrollPassThrough> | — |
| The pass-through props to pass to the component. | ||
ptOptions | PassThroughOptions | — |
| The pass-through options to pass to the component. | ||
unstyled | boolean | — |
| Whether the component should be rendered without classes. | ||
dt | unknown | — |
| The design token to use for the component. | ||
styles | StylesOptions<ComponentInstance> | — |
| The styles to use for the component. | ||
render | (instance: AnimateOnScrollInstance) => ReactNode | — |
| The render function to render the component with instance access. | ||
children | any | — |
| The children to render. Accepts `React.ReactNode` for static content or a render function `(instance: I) => React.ReactNode` for instance access. Typed as `any` to avoid JSX type errors when used directly in templates. | ||
enterClassName | string | — |
| CSS class names that are applied when the element enters the viewport. | ||
leaveClassName | string | — |
| CSS class names that are applied when the element leaves the viewport. | ||
once | boolean | false |
| When enabled, animation is triggered only once. | ||
[key: string] | any | — |
pt-{optionName}-* | - | — |
| Pass through attributes for customizing component. For more info, see Pass Through tab. | ||
| Attribute | Value |
|---|---|
data-scope | "animateonscroll" |
data-part | "root" |
Defines passthrough(pt) options of AnimateOnScroll component.
| label | type | description |
|---|---|---|
| root | AnimateOnScrollPassThroughType<HTMLAttributes<HTMLDivElement>> | Used to pass attributes to the root's DOM element. |
Accessibility#
Screen Reader#
AnimateOnScroll does not require any roles and attributes.
Keyboard Support#
Component does not include any interactive elements.