Scroll Areas let you add custom, consistent scrollbars to any content. They're great for creating scrollable sections within your page.
To use the Astra Scroll Area component, wrap your content with the <astra-scroll-area>
tag:
<astra-scroll-area>
<div class="h-[1200px] w-[2400px] bg-green-500">
<!-- Your scrollable content here -->
</div>
</astra-scroll-area>
The Astra Scroll Area component offers some useful options:
Control the scroll direction using the axis
attribute:
<astra-scroll-area axis="vertical">
<!-- Vertical scrolling content -->
</astra-scroll-area>
<astra-scroll-area axis="horizontal">
<!-- Horizontal scrolling content -->
</astra-scroll-area>
<astra-scroll-area axis="both">
<!-- Both vertical and horizontal scrolling content -->
</astra-scroll-area>
Use the onScroll
and threshold
attributes to handle scroll events:
<astra-scroll-area onScroll="handleScroll" threshold="100">
<!-- Scrollable content -->
</astra-scroll-area>
<script>
function handleScroll() {
console.log('Scrolled more than 100 pixels');
}
</script>
The Astra Scroll Area component is built with accessibility in mind: