Observe Panel Resize
Use the observePanelResize option to attach a ResizeObserver to each panel element, so that Flicking automatically recalculates the layout when a panel's size changes.
Try clicking the "Expand" button inside a panel to see the difference between the two carousels.
- JavaScript
- React
- Vue@3
Summary
Key Options
| Option | Type | Default | Description |
|---|---|---|---|
observePanelResize | boolean | false | Detect panel element size changes via ResizeObserver |
Dependent Option
observePanelResize only works when useResizeObserver is true. Since the default value of useResizeObserver is true, it can be used without additional configuration.
Value Comparison
| Value | Behavior | Best For |
|---|---|---|
false | Only detects viewport size changes (default) | Typical carousels with fixed panel sizes |
true | Also detects per-panel size changes, auto-recalculates | Dynamic content, image loading, accordion panels |
Details
How observePanelResize Works
By default, Flicking's autoResize only detects size changes on the viewport (container) element. Even if the content inside a panel changes and the panel itself resizes, Flicking is unaware of it.
Setting observePanelResize: true attaches a ResizeObserver to each panel element. As soon as a panel's size changes, beforeResize / afterResize events are fired and the layout is recalculated.
const flicking = new Flicking("#el", {
observePanelResize: true
// useResizeObserver: true (default, can be omitted)
});
Use Cases
- Panels with images: When panels grow to their actual size after image load completes
- Accordion/toggle panels: When panel height changes due to user interaction
- Dynamic content: When content is added to panels after an API response, changing their size
- With
adaptive: true: When viewport height adapts to the active panel height and panel content changes dynamically
observePanelResize: true attaches a ResizeObserver to every panel, which can introduce some overhead when there are many panels. For typical carousels with fixed panel sizes, keep the default (false).
resizeOnContentsReady is an option that waits once for image/media load completion during initialization. observePanelResize continuously monitors panel sizes even after initialization. Choose based on your use case as they serve different purposes.
Related Links
Related Options
useResizeObserver: Whether to use ResizeObserver (dependent option)autoResize: Auto recalculate on viewport size changeresizeOnContentsReady: Resize after initial content load completesadaptive: Auto-adjust viewport height
Related Demos
- Adaptive: Auto-adjust viewport height
- Auto Resize: Resize detection method settings
- Resize Debounce: Control resize call frequency