Skip to main content

Prev / Next

Use isReachStart, isReachEnd, and moveTo from the Reactive API to build navigation buttons that automatically disable at the carousel boundaries.

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

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

const prevBtn = document.querySelector("#prev-btn");
const nextBtn = document.querySelector("#next-btn");

prevBtn.addEventListener("click", () => {
  if (!reactiveAPI.isReachStart) {
    reactiveAPI.moveTo(flicking.index - 1);
  }
});

nextBtn.addEventListener("click", () => {
  if (!reactiveAPI.isReachEnd) {
    reactiveAPI.moveTo(flicking.index + 1);
  }
});

// Update button state
reactiveAPI.subscribe("isReachStart", value => {
  prevBtn.disabled = value;
});

reactiveAPI.subscribe("isReachEnd", value => {
  nextBtn.disabled = value;
});

Summary

Key API

Property / MethodTypeDescription
isReachStartbooleanWhether the first panel is active
isReachEndbooleanWhether the last panel is active
currentPanelIndexnumberCurrently active panel index
moveTo(i: number) => PromiseMove to a specific panel

Button States

PositionPrev ButtonNext Button
First panel (isReachStart)disabledenabled
Middle panelenabledenabled
Last panel (isReachEnd)enableddisabled

Details

How It Works

  • Disable the Prev button when isReachStart is true
  • Disable the Next button when isReachEnd is true
  • Prev click: moveTo(currentPanelIndex - 1)
  • Next click: moveTo(currentPanelIndex + 1)
  • Button states auto-sync when the user drags to a new panel
  • circular: true: In circular mode, isReachStart and isReachEnd are always false, so both buttons remain enabled at all times.

Use Cases

When to use
  • Desktop carousels where drag is less discoverable
  • Accessibility (a11y) keyboard/button navigation
  • Touch-disabled environments