Skip to main content

Scroll Class Toggle

The ScrollClassToggle is a client-side component that will toggle its classes when it is reached in the viewport. It can be used to toggle element positioning or styles on scroll.

The enableAtElement property controls when the toggle happens. If set to false, the toggle will happen immediately based on the element's height. If set to true, the toggle will happen when the element is scrolled to the top. The default is false.

Example

On scroll, this element's background color will be toggled.

Props

NameDescriptionType
classNameInitial styles for the element.String
toggleClassStyles to apply to the element on scrollString
enableAtElementWhen to apply the toggle. Default is false.Boolean
propsAdditional properties from HTML Button attributes.ButtonHTMLAttributes