Skip to main content

Pagination

Use currentPanelIndex, totalPanelCount, and moveTo from the Reactive API to build a dot pagination UI that stays in sync with the carousel.

import Flicking, { connectFlickingReactiveAPI } from "@egjs/flicking";
import "@egjs/flicking/dist/flicking.css";
import "./styles.css";

const flicking = new Flicking("#flick");
const reactiveAPI = connectFlickingReactiveAPI(flicking);

// Create pagination buttons
const pagination = document.querySelector(".pagination");
const buttons = [];

for (let i = 0; i < reactiveAPI.totalPanelCount; i++) {
  const btn = document.createElement("button");
  btn.className = `pagination-btn${i === 0 ? " active" : ""}`;
  btn.textContent = i + 1;
  btn.addEventListener("click", () => reactiveAPI.moveTo(i));
  buttons.push(btn);
  pagination.appendChild(btn);
}

// Update active button on index change
reactiveAPI.subscribe("currentPanelIndex", index => {
  buttons.forEach((btn, i) => {
    btn.classList.toggle("active", i === index);
  });
});

Summary​

Key API​

Property / MethodTypeDescription
currentPanelIndexnumberCurrently active panel index
totalPanelCountnumberTotal number of panels
moveTo(i: number) => PromiseMove to a specific panel

Behavior​

StateDot Style
Current panelActive (highlighted)
Other panelsDefault, click to navigate

Details​

How It Works​

  1. Render dot buttons based on totalPanelCount
  2. Highlight the dot matching currentPanelIndex
  3. On dot click, call moveTo(index) to navigate
  4. When the user drags to a new panel, currentPanelIndex updates automatically and the dots re-sync
  • align: "center": Center alignment makes pagination feel most intuitive.
  • circular: true: In circular mode, dots cycle seamlessly as the first and last panels connect.

Use Cases​

When to use
  • Banner / hero slider position indicator
  • Image gallery page indicator
  • Mobile onboarding step dots