Resize On Contents Ready
Use the resizeOnContentsReady option to automatically recalculate panel size and position after images/videos have loaded.
- JavaScript
- React
- Vue@3
Summary
Key Options
| Option | Type | Default | Description |
|---|---|---|---|
resizeOnContentsReady | boolean | false | Automatically recalculate panel size when content loads |
Mode Comparison
| resizeOnContentsReady | Behavior After Image Load |
|---|---|
false | Flicking's internal panel size stays as it was at initialization — scroll range and snap positions become misaligned |
true | Panel size is recalculated — scroll range and snap positions are correct |
Details
How It Works
- Panel sizes are calculated at Flicking initialization
- Images/videos have not loaded yet, so sizes are 0 or placeholder size
- After image load completes, the actual size changes
- With
resizeOnContentsReady: true, panel sizes are automatically recalculated and positions updated via@egjs/imready
<Flicking
resizeOnContentsReady={true}
>
<div className="panel">
<img src="image.jpg" /> {/* Panel size automatically recalculated when load completes */}
</div>
</Flicking>
What Gets Recalculated
When resizeOnContentsReady detects image/video load, the following are updated:
- Panel size (
panel.resize()) - Subsequent panel positions (
updatePosition()) - Camera scroll range (
camera.updateRange()) - Snap points (
camera.updateAnchors())
Detected Content Types
Load events are detected for the following elements within panels:
<img>images<video>videos
Use Cases
When should you use resizeOnContentsReady?
Recommended:
- When panel size depends on images/videos
- When panel size is not pre-fixed with CSS
- When loading images from the network
Not necessary:
- When panel size is pre-fixed with CSS (e.g.,
width: 200px) - Text-only panels
- When images are included as base64 inline
Manual resize Alternative
When resizeOnContentsReady: false, you can manually call resize:
// Manual resize after image load completes
img.addEventListener("load", () => {
flicking.resize();
});
Related Links
Related Options
adaptive: Auto-adjust viewport heightautoResize: Auto resize on window resize
Related Methods
resize: Manual layout recalculation
Related Demos
- Adaptive: Adaptive option demo