Wrap any content inside this Sticky component to make it stick to the top edge of its scroll container. When stuck, the data-state="stuck" is added which you can use for state-based styling.
Any Sticky component only sticks when its height is smaller than its scolling container. User the tolerance property to add to the calculated required height which helps you tweak the desired behavior in certain situations.
'tolerance' => 0,
<style> #sample-sticky[data-state="stuck"] div { background: var(--color-positive-600); } </style> <x-scrollClip class="h-[400px]" signifiers="outside"> <div class="h-[240px]"></div> <x-sticky id="sample-sticky"> <div class="size-[80px] mx-auto rounded-xs bg-neutral-600"></div> </x-sticky> <div class="h-[960px]"></div> </x-scrollClip>
<x-scrollClip class="h-[400px]" signifiers="outside"> <div class="h-[240px]"><!-- spacer --></div> {{-- Even though there is enough vertical space for the element to stick, the tolerance value prevents sticking since it adds to the calculated required space. Therefore, the element does not stick. --}} <x-sticky tolerance="48"> <div class="w-[80px] h-[360px] mx-auto rounded-xs bg-neutral-600"></div> </x-sticky> <div class="h-[960px]"><!-- spacer --></div> </x-scrollClip>