User avatar

Jeroen Reumkens PRO

Motion for React – Pausing animations with delay

Unlock Playground Access

Playgrounds let you build, test, and share frontend ideas instantly — right in your browser. Access is included in PRO. Just want Playgrounds? Pick a plan below.

Maker

€5,- / month

Unlimited Playgrounds access to build, experiment, and share without limits.

Join for €5 per month

Champion

€10,- / month

All the benefits of Maker, plus you help Frontend.fyi grow and get a Champion badge on your profile.

Join for €10 per month

Cancel anytime — no commitment.
Upgrade to PRO anytime and get a partial refund.We'll credit 100% of your first 3 months and 50% of the rest toward the PRO lifetime price.

Already a member? Login

Playground settings

Title

Description

Public

Editor settings


Packages

These packages can be imported in your JavaScript files.

Package name

Version

@

@

@

123456789101112131415161718192021222324252627282930313233343536373839404142434445
import { useAnimate, stagger } from "motion/react";
import { useEffect, useState, useRef } from "react";

export const App = () => {
  const [scope, animate] = useAnimate();
  const [count, setCount] = useState(0);
  const animation = useRef(null);

  useEffect(() => {
    animation.current = animate(
      ".thingy",
      { 
        y: [0, "50%", "50%", 0, 0]
      },
      { repeat: Infinity, duration: 2.5, delay: stagger(-1.25) },
    );
  }, []);

  return (
    <div className="grid min-h-dvh place-items-center" ref={scope}>
      <div className="grid [&_*]:[grid-area:1/1] place-items-center">
        <div className="thingy w-36 h-36 border-2 border-white rounded-full origin-center"/>
        <div className="thingy w-36 h-36 bg-white rounded-full origin-center"/>
      </div>
      
      <div className="flex gap-8">
        <button
          className="rounded-md bg-white px-4 py-2 text-black"
          onClick={() => animation.current?.play()}
        >
          Play
        </button>
        <button
          className="rounded-md bg-white px-4 py-2 text-black"
          onClick={() => animation.current?.pause()}
        >
          Stop
        </button>
      </div>
    </div>
  );
};

export default App;
One sec — editor's thinking…