Introducing PrimeReact v11-alpha 🎉Discover Now

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 enterClassName when the element scrolls into view and leaveClassName when it scrolls out
  • Configurable Intersection Observer options: root, rootMargin, threshold
  • once mode to trigger animation only on first viewport entry
  • Automatic cleanup of animation classes after animationend and transitionend events

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#

NameTypeDefault
refRef<unknown>—
The reference to the component instance.
pIfbooleantrue
Whether the component should be rendered.
styleCSSProperties | ((instance?: AnimateOnScrollInstance) => CSSProperties)—
The style to apply to the component.
classNamestring | ((instance?: AnimateOnScrollInstance) => string)—
The class name to apply to the component.
asstring | 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.
asChildbooleanfalse
Whether the component should be rendered as a child component.
instanceAnimateOnScrollInstance—
The instance to pass to the component.
ptSafeRecord<AnimateOnScrollPassThrough>—
The pass-through props to pass to the component.
ptOptionsPassThroughOptions—
The pass-through options to pass to the component.
unstyledboolean—
Whether the component should be rendered without classes.
dtunknown—
The design token to use for the component.
stylesStylesOptions<ComponentInstance>—
The styles to use for the component.
render(instance: AnimateOnScrollInstance) => ReactNode—
The render function to render the component with instance access.
childrenany—
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.
enterClassNamestring—
CSS class names that are applied when the element enters the viewport.
leaveClassNamestring—
CSS class names that are applied when the element leaves the viewport.
oncebooleanfalse
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.
AttributeValue
data-scope"animateonscroll"
data-part"root"

Defines passthrough(pt) options of AnimateOnScroll component.

labeltypedescription
rootAnimateOnScrollPassThroughType<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.