Percentage Position
Apply the camera element's transform position as a percentage value (%) instead of px using the usePercentagePos option.
The demo below disables autoResize to simulate the moment before resize() is applied. Toggle the container width and compare the two carousels — the px-positioned one gets misaligned until resize() is called, while the %-positioned one keeps its relative position.
- JavaScript
- React
- Vue@3
Summary
Key Options
| Option | Type | Default | Description |
|---|---|---|---|
usePercentagePos | boolean | false | Apply the camera position as a percentage value (%) instead of px |
Behavior Comparison
| Setting | Camera transform | On viewport size change (before resize) |
|---|---|---|
usePercentagePos: false | translate(-832px) | Camera stays at the same px position, so panels get misaligned |
usePercentagePos: true | translate(-104%) | Camera keeps its relative position, so panels stay in place |
Details
How It Works
When enabled, Flicking calculates the camera position as a percentage relative to the viewport size and applies it as transform: translate(-104%) instead of translate(-832px).
Since a percentage position scales together with the viewport, the camera keeps its relative position even before the internal sizes are recalculated by resize(). When the panels are also sized with relative units (%-based widths and margins like this demo), the whole layout stays visually aligned during viewport size changes.
Related Options
- Relationship with
autoResize: In real-world usage you'd keepautoResizeenabled.usePercentagePosprevents the temporary misalignment between the moment the layout changes and the moment the (possibly debounced) resize call is applied. This demo disables it only to make that in-between moment observable. - Relationship with
resizeDebounce: With a largeresizeDebouncevalue, the gap until resize is applied gets longer.usePercentagePoskeeps panels in place during that gap.
Use Cases
- Responsive (%-based) layouts: Panels keep their position while the container size changes, such as during window resizes or CSS transitions
- Debounced resize: Prevents visible misalignment during the debounce delay when using
resizeDebounce
Notes
- The percentage position keeps panels visually aligned only when the panel sizes are also relative to the viewport (e.g.,
%-based widths). Panels with fixed px sizes will still be misaligned untilresize()is called. - This option only changes how the camera position is applied. The internal sizes are not updated automatically —
resize()still has to be called (orautoResizekept enabled) to update the input areas and movement boundaries.
Related Links
Related Options
autoResize: Automatic resize detectionresizeDebounce: Resize call debounceuseFractionalSize: CSS-computed fractional sizes
Related Methods
resize: Recalculate the internal sizes
Related Demos
- Resize Debounce: Control resize call frequency
- Auto Resize: Resize detection method settings