Skip to main content

Carousel

Combine the circular, panelsPerView, and align options to build various carousel UIs.

import Flicking from "@egjs/flicking";
import "@egjs/flicking/dist/flicking.css";
import "./styles.css";

const COLORS = ["#e74c3c", "#3498db", "#2ecc71", "#f39c12", "#9b59b6", "#1abc9c", "#e67e22", "#2980b9"];

function createPanels(containerId) {
  const camera = document.querySelector(`#${containerId} .flicking-camera`);
  COLORS.forEach((color, i) => {
    const panel = document.createElement("div");
    panel.className = "flicking-panel";
    panel.style.background = color;
    panel.textContent = i + 1;
    camera.appendChild(panel);
  });
}

createPanels("flick1");
createPanels("flick2");
createPanels("flick3");

new Flicking("#flick1", {
  circular: true,
  panelsPerView: 3,
  align: "prev"
});

new Flicking("#flick2", {
  circular: true,
  panelsPerView: 1,
  align: "center"
});

new Flicking("#flick3", {
  circular: false,
  panelsPerView: 3,
  align: "prev",
  bound: true
});

Summary

Key Options

OptionTypeDefaultDescription
circularbooleanfalseCircular mode
panelsPerViewnumber-1Number of panels per view (-1 to disable)
alignstring | number"center"Panel alignment position

Combination Comparison

CombinationBehaviorBest For
circular + panelsPerView: 3 + align: "prev"Infinite loop showing 3 panelsProduct lists, card carousels
circular + panelsPerView: 1 + align: "center"Infinite loop with 1 center-aligned panelHero sliders, banners
circular: false + panelsPerView: 3 + bound3-column slider with end boundariesFinite lists, galleries

Details

circular + panelsPerView Combination

When using circular: true together with panelsPerView, the specified number of panels are visible on screen while looping infinitely. Panel width is automatically calculated as 100% / panelsPerView.

Role of align

  • "prev": Panels are left-aligned — suitable for list-type carousels
  • "center": Current panel is centered — suitable for spotlight-type carousels

Non-Circular Slider

Setting circular: false + bound: true creates a regular slider that stops without empty space at the end.

  • Relationship with circularFallback: Sets fallback behavior when there are not enough panels for circular mode
  • Relationship with bound: Use bound: true with circular: false to prevent empty space
  • Relationship with noPanelStyleOverride: When using panelsPerView, you can disable automatic panel width setting and control it directly with CSS

Use Cases

When should you use this?
  • Product carousel: circular + panelsPerView: 3~5 combination
  • Hero banner: circular + panelsPerView: 1 + align: "center" combination
  • Image gallery: circular: false + panelsPerView: 3 + bound combination

Notes

Caution
  • For circular: true to work, the total panel width must be larger than the viewport. If there are not enough panels, check the circularFallback setting.
  • When panelsPerView is set, the panel's CSS width is automatically overridden. Setting a separate width in CSS may cause conflicts.