egjs-flicking
repository·master·Indexed 25 days ago
https://github.com/naver/egjs-flickingA reliable, flexible, and extendable carousel component for modern web development. It supports SSR, circular mode, free scroll, and virtual scrolling. The project provides a core library (@egjs/flicking), a plugin system (@egjs/flicking-plugins) for effects like AutoPlay and Parallax, and official wrappers for React (@egjs/react-flicking) and Vue 3 (@egjs/vue3-flicking).
What's inside egjs-flicking
- @egjs/flicking is the core library of the Flicking project. It contains the primary logic for the flicking engine, including TypeScript source files and SASS styles.
Overview of Flicking Packages
masterFlicking is a monorepo containing the core library and framework-specific ports:
Package Description @egjs/flicking Core carousel library @egjs/flicking-plugins Readymade effects (AutoPlay, Fade, Parallax, Arrow, Pagination) @egjs/react-flicking React port @egjs/vue3-flicking Vue 3 port Understand the Documentation Versioning and Deployment Policy
masterThe project uses a custom documentation versioning strategy instead of Docusaurus's built-in
docs:versionfeature to avoid build bloat and duplicate files.Key Principles:
- Major Versions Only: Static builds are archived only at the major version level.
- Always Latest Minor: The
docs/directory always reflects the latest minor version; snapshots are not created for every minor/patch release. - Automated Release Notes: GitHub Releases are automatically converted into Docusaurus Blog posts via
scripts/fetch-releases.js.
Understand the API documentation generation pipeline
masterWhen running
pnpm api-docs:generate, the following pipeline is executed:- Type declaration files (
.d.ts) are generated forpackages/flickingandpackages/flicking-plugins. api-extractorruns and savesflicking.api.jsonandflicking-plugins.api.jsoninto theapi-artifacts/directory.- The documentation generator runs to produce the final markdown files.
- Type declaration files (
Understand the Claude Code Harness Architecture
masterThe Claude Code harness for this project is organized into three layers to manage rules, enforcement, and specialized workflows:
- AGENTS.md: Core rules and entry points (always loaded, located at the root).
- Hooks: Physical enforcement of rules (deterministic actions, configured in
.claude/settings.json). - Skills: Workflows and domain knowledge (loaded as needed, located in
.claude/skills/). - Subagents: Isolated context for verification tasks (located in
.claude/agents/).
Implement Pagination HTML structure
masterThe pagination element must be placed inside the viewport. The standard HTML structure is:
<div class="flicking-viewport"> <div class="flicking-camera"> <!-- Panels --> </div> <div class="flicking-pagination"></div> </div><div class="flicking-viewport"> <div class="flicking-camera"> <!-- Panels --> </div> <div class="flicking-pagination"></div> </div>Create a parallax effect using indexProgress
masterYou can implement a parallax scrolling effect by utilizing the
indexProgressproperty from the Reactive API. This property provides the camera position as a fractional panel index, allowing you to calculate how far each panel is from the center.To achieve the effect, calculate a
childProgressfor each panel using the formula:childProgress = panelIndex - indexProgress.You can then map this value to visual properties:
- Horizontal Offset: Translate elements by
childProgress * offset. Using different offset values for different layers creates a sense of depth. - Opacity: Fade elements from
1.0(at the current panel) to0.0(at adjacent panels) based on the absolute value ofchildProgress.
For smoother continuous parallax transitions, use
moveType: "freeScroll".- Horizontal Offset: Translate elements by
Style the Flicking viewport
masterThe viewport controls the visible area of the carousel. How you apply styles depends on your framework:
- Vanilla JavaScript: You must manually create the
.flicking-viewportelement and add your custom class to it. - React/Vue3: The component renders as
.flicking-viewportautomatically. Apply your custom class directly to the<Flicking>component viaclassName(React) orclass(Vue3).
// React example <Flicking className="my-carousel"> <div className="panel">Panel 1</div> </Flicking> /* CSS */ .my-carousel { max-width: 1200px; margin: 0 auto; border-radius: 8px; }- Vanilla JavaScript: You must manually create the
Build dot pagination using the Reactive API
masterYou can build a custom dot pagination UI that stays in sync with a Flicking carousel by using the Reactive API. This involves monitoring the current panel index and the total number of panels to render and highlight dots, then using the
moveTomethod to navigate when a dot is clicked.Implementation Logic
- Render dot buttons based on
totalPanelCount. - Highlight the dot that matches the
currentPanelIndex. - On dot click, call
moveTo(index)to navigate to that specific panel. - The
currentPanelIndexupdates automatically when the user drags to a new panel, ensuring the dots re-sync.
Recommended Configuration
align: "center": Using center alignment makes pagination feel most intuitive.circular: true: In circular mode, dots cycle seamlessly as the first and last panels connect.
- Render dot buttons based on
Register @egjs/vue3-flicking locally
masterTo use the Flicking component only within a specific component, register it locally in the
componentsoption.import Flicking from "@egjs/vue3-flicking"; export default { components: { Flicking: Flicking, } }Install @egjs/flicking via CDN
masterYou can use Flicking via CDN providers:
- jsDelivr:
https://cdn.jsdelivr.net/npm/@egjs/flicking/dist/ - unpkg:
https://unpkg.com/@egjs/flicking/dist/ - cdnjs:
https://cdnjs.com/libraries/egjs-flicking
- jsDelivr:
Implement 2D cross-directional carousels with CrossFlicking
masterUse the
CrossFlickingpreset class to build a 2D carousel where users swipe horizontally to switch between groups and vertically to browse items within a group.DOM Structure Requirements
To function correctly, your HTML must follow this structure:
- A viewport element (the container).
- A camera element (the direct child of the viewport).
- Group wrappers (direct children of the camera). Each group wrapper's children become the vertical items for that group.
Implementation Pattern
For React and Vue, it is recommended to instantiate the core class imperatively within lifecycle hooks (
useEffectoronMounted) rather than using component wrappers to avoid initialization issues.Note: Ensure the viewport has an explicit height, as the vertical side instances require a fixed layout height to function.
import { CrossFlicking } from "@egjs/flicking"; // Initialize the 2D carousel new CrossFlicking("#cross", { align: "prev", moveType: "strict", bound: true, sideOptions: { moveType: "strict", bound: true } });<div id="cross" class="flicking-viewport"> <div class="flicking-camera"> <!-- group: Nature --> <div class="group-wrapper"> <div class="cross-panel">Forest</div> <div class="cross-panel">Meadow</div> </div> <!-- group: Ocean --> <div class="group-wrapper"> <div class="cross-panel">Reef</div> <div class="cross-panel">Wave</div> </div> </div> </div>