Code

GSAP

FLIP

AdvancedFirst, Last, Invert, Play — capture element positions, change the layout, then animate smoothly between states with Flip.from(). GSAP Docs

A
B
C
D
E
F
import { Flip } from 'gsap/Flip';

gsap.registerPlugin(Flip);

function shuffle() {
  // 1. Snapshot current positions
  const state = Flip.getState(items);

  // 2. Change the DOM layout freely
  items.sort(() => Math.random() - 0.5)
       .forEach(el => container.appendChild(el));

  // 3. Animate from snapshot → new positions
  Flip.from(state, {
    duration: 0.7,
    ease: 'power1.inOut',
    stagger: 0.05,
  });
}

setInterval(shuffle, 1600);