Embla Carousel
repository·master·Indexed 11 days ago
https://github.com/davidjerleke/embla-carouselA lightweight, dependency-free, and framework-agnostic carousel library focused on smooth motion and precision swiping. Version 9.0.0-rc02 provides a core engine with official wrappers for React, Vue, Svelte, and Solid, as well as community support for Angular. It includes a variety of plugins such as Autoplay, Auto Scroll, Auto Height, Fade, Accessibility, and Class Names, and offers specialized utilities for Server-Side Rendering (SSR) and reactive frameworks.
What's inside Embla Carousel
- Embla Carousel SSR is a specialized module for the Embla Carousel library designed to support Server-Side Rendering (SSR) environments. While the core Embla Carousel is a lightweight, dependency-free, and framework-agnostic library focused on smooth motion and precision swiping, the SSR package provides the necessary utilities to ensure carousel functionality and state are correctly handled during server-side rendering processes.
Overview of Embla Carousel
masterEmbla Carousel is a lightweight, dependency-free carousel library designed for smooth, fluid motion and precision swiping. It is framework-agnostic, meaning it can be used with vanilla JavaScript/TypeScript or integrated into various modern UI frameworks. It is built to provide developers with complete control over carousel behavior without unnecessary bloat.Overview of Embla Carousel Vue
masterEmbla Carousel Vue is a wrapper for Embla Carousel, a lightweight, dependency-free carousel library designed for smooth, fluid motion and precision swiping. It allows Vue developers to implement high-performance carousels with complete control over the motion and behavior.Overview of Embla Carousel Reactive Utils
masterEmbla Carousel Reactive Utils is a package designed to work with the Embla Carousel library. Embla Carousel itself is a lightweight, dependency-free, framework-agnostic carousel library focused on smooth motion and precision swiping. The reactive utils package provides additional functionality to help integrate Embla Carousel more seamlessly with reactive frameworks.Overview of Embla Carousel React
masterEmbla Carousel React is a React-specific wrapper for Embla Carousel, a lightweight, dependency-free carousel library. It is designed for smooth, fluid motion and precision swiping, providing developers with complete control over carousel behavior without unnecessary bloat. It is built to be framework-agnostic at its core but offers optimized hooks and components for React integration.Overview of Embla Carousel Auto Height plugin
masterTheembla-carousel-auto-heightpackage is a plugin for Embla Carousel that enables the carousel to automatically adjust its height based on the content of the currently active slide. This is useful when slides have varying heights and you want the carousel container to resize smoothly to fit the active content.Manage button disabled state for non-looping carousels
masterIn non-looping carousels, it is good UX to disable navigation buttons when the carousel reaches the first or last slide. To implement this, listen to the following Embla events to update your button state:
select: Fires when the selected scroll snap changes.reInit: Fires when the carousel resets.
Note on Looping Carousels: In looping carousels with enough slides to wrap around, the
scrollPrevandscrollNextmethods always trigger scrolling, so buttons are never disabled.Understand Embla Carousel's DOM manipulation model
masterEmbla Carousel is designed for high performance by using minimal DOM manipulation. It does not encapsulate or wrap your elements, meaning you retain full control over your markup and structure.
Embla only modifies the DOM in two specific ways:
- Carousel container: Applies
translate3dto create the scrolling effect. - Carousel slides: Applies
translate3dto adjust slide positions (primarily for looping functionality).
Because Embla uses inline styles for these properties, it is compatible with all frameworks and allows for highly custom layouts. Note that while the core library and official framework wrappers follow this minimal approach, certain plugins may modify the DOM further.
- Carousel container: Applies
Extend carousel functionality with plugins
masterPlugins allow you to add advanced features to your Embla Carousel instance. Common plugin-based features include:
- Autoplay: Automatically advances the carousel slides.
- Auto Scroll: Creates a continuous, smooth scrolling effect.
- Auto Height: Automatically adjusts the carousel container height based on the current slide.
- Fade: Changes the transition effect from sliding to a fade transition.
- Class Names: Provides CSS class names for different carousel states (e.g.,
selected,inactive) to facilitate styling.
How Embla Carousel handles slide sizes
masterEmbla Carousel does not assign slide sizes directly. Instead, it measures the computed dimensions of your slides as determined by your CSS. This allows you to use any layout method (Flexbox, Grid, etc.) and any CSS units.
Key Requirements:
- Slides must stack along the carousel's scroll axis (horizontally for horizontal carousels, vertically for vertical carousels).
- You have full control over widths, heights, and layout methods via CSS.
How to use Embla Carousel methods
masterEmbla Carousel provides methods to programmatically extend and control the carousel.
Key Requirements:
- Methods require an initialized carousel instance.
- Methods are accessible only while the instance is active. They become invalid after calling
destroy.
To use methods, you typically access the instance returned by the Embla initialization function (or via framework-specific hooks like
useEmblaCarouselin React) and call the desired method on that instance.// Example: Accessing methods in Vanilla JS const emblaApi = emblaApi; if (emblaApi) { console.log(emblaApi.slideNodes()); }Cancel events in Embla Carousel
masterSome events are cancellable, allowing you to prevent Embla Carousel's internal logic from executing. To cancel an event, your event handler must return
false. Returning any other value (liketrueorundefined) allows the event to proceed normally.// Example: Preventing dragging if allowPointerDownEvent is false emblaApi.on('pointerdown', () => { if (!allowPointerDownEvent) return false })