Add / Remove
Dynamically add or remove panels using the prepend(), append(), and remove() API methods.
- JavaScript
- React
- Vue@3
Summary
Key API Methods
| Method | Signature | Description |
|---|---|---|
append | append(element): Panel[] | Add after the last panel |
prepend | prepend(element): Panel[] | Add before the first panel |
remove | remove(index, count?): Panel[] | Remove panel at specified index |
Behavior Comparison
| Method | Index Change | Best For |
|---|---|---|
prepend | Existing panel indices increase by +1 | Adding latest items to the front |
append | Existing panel indices unchanged | Adding new items to the end of a feed |
remove | Indices after removed panel decrease by -1 | Deleting items |
Details
Framework-Specific Patterns
React / Vue: Manipulate the panel array through the framework's state management. Flicking detects state changes and automatically updates panels.
Vanilla JS: Directly call the prepend(), append(), remove() methods on the Flicking instance. You can pass an HTMLElement or an outerHTML string as the element parameter.
Related Options
- Relationship with
renderOnlyVisible: When there are many panels, usingrenderOnlyVisible: truetogether maintains performance even with dynamic additions - Relationship with
needPanelThreshold: Can be combined with theneedPanelevent to implement an infinite scroll pattern
Use Cases
When should you use this?
- Social media feeds:
prependnew posts to the front,appendolder posts to the back - E-commerce product lists: Remove/add panels based on filtering
- Dashboard widgets: Add/remove widgets
Notes
Caution
- When using
prepend, all existing panel indices increase by 1. Be careful if you have logic that depends on indices. - If the currently visible panel is removed after a
remove, it automatically moves to an adjacent panel. - In React/Vue, each panel must have a unique
keyto work properly.
Related Links
Related API
Related Demos
- Infinite Scroll: Automatic panel addition with the
needPanelevent - Lazy Load: Optimization pattern used with
renderOnlyVisible