Skip to main content

Parallax

Use indexProgress from the Reactive API to create a parallax effect where inner elements move at different speeds based on the panel's distance from the camera center.

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

const OFFSETS = [180, 160, 140, 120, 100];

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

const panels = document.querySelectorAll(".skeleton-panel");

const update = value => {
  panels.forEach((panel, index) => {
    const childProgress = index - value;
    const opacity = Math.min(Math.max(1 - Math.abs(childProgress), 0), 1);

    const bars = panel.querySelectorAll(".skeleton-bar");
    bars.forEach((bar, i) => {
      bar.style.transform = `translateX(${childProgress * OFFSETS[i]}px)`;
      bar.style.opacity = opacity;
    });
  });
};

// Apply initial state and subscribe to changes
update(reactiveAPI.indexProgress);
reactiveAPI.subscribe("indexProgress", update);

Summary

Key API

PropertyTypeDescription
indexProgressnumberCamera position as a fractional panel index

Effect Mapping

Panel PositiontranslateXOpacity
Current (childProgress = 0)0px1.0
Adjacent (childProgress = ±1)±offset0.0

Details

How It Works

Each panel contains skeleton bar elements. The childProgress for each panel is calculated as panelIndex - indexProgress. This value drives two visual effects:

  1. Horizontal offset: Each bar translates by childProgress * offset, where different bars have different offset values (100-180px), creating a layered depth effect.
  2. Opacity: Fades from 1 (current panel) to 0 (adjacent panels) based on |childProgress|.

The varying offsets per bar create the signature parallax look: elements closer to the "camera" appear to move faster than those further away.

  • moveType: "freeScroll": Produces smoother continuous parallax as the user scrolls freely.
  • Default moveType (snap): Parallax still works but snaps between discrete panel positions.

Use Cases

When to use
  • Card-based content with layered elements
  • Storytelling / editorial carousels
  • Product showcase with depth effect