Features
- Infinite Scrolling: Seamlessly loops through items without visual interruption
- Autoplay: Automatically advances slides every 4 seconds
- Navigation Controls: Previous/next arrow buttons with hover effects
- Pause on Hover: Autoplay pauses when user hovers over the carousel
- Responsive Design: Adapts to different screen sizes with appropriate spacing
- Accessibility: Proper ARIA labels on navigation buttons
Usage
Basic Implementation
With Images
Props
The Carousel component uses Astro’s slot pattern and doesn’t accept direct props. All content is passed through the default slot.The carousel items to display. Each child element will be wrapped in a carousel item container.
Structure
Component Layout
The carousel consists of:- Main Container:
.sets-carousel- Outer wrapper with relative positioning - Overflow Container: Handles visual clipping with rounded corners
- Slider:
.flex- The moving container that holds all items - Navigation Buttons:
.prev-btnand.next-btn- Arrow controls
Generated Classes
Each slotted child is automatically wrapped with:Behavior
Infinite Scrolling Logic
The carousel creates clones of the first and last items:- First clone is appended to the end
- Last clone is prepended to the beginning
- When reaching a clone, the carousel instantly jumps to the real item without transition
Autoplay Configuration
Styling
Navigation Buttons
The arrow buttons feature:- Semi-transparent black background (
bg-black/50) - White inverted arrow icons
- Scale animation on hover (125%)
- Disabled state with reduced opacity
- Responsive positioning for different breakpoints
Customization Classes
Animation
The carousel uses CSS transforms for smooth transitions:Transition Details
- Duration: 0.5 seconds
- Easing: ease-in-out
- Method: translateX percentage-based positioning
The carousel automatically hides navigation buttons if there is only one item or if the necessary elements are not found.
Accessibility
ARIA Labels
Disabled States
Buttons include proper disabled states:disabled:cursor-not-alloweddisabled:opacity-20
Advanced Features
Animation Lock
The component prevents multiple simultaneous animations:Astro Page Load Integration
The carousel reinitializes on Astro page transitions:This ensures the carousel works correctly with Astro’s View Transitions API.
Browser Compatibility
The carousel uses modern JavaScript features:- CSS transforms
- Template literals
- Arrow functions
- querySelector API
- Event listeners