React AnimeJS
Advanced Playgrounds

Interactive example

Scope

constructor function + defaults

Uses scope construction with conditional behavior based on container width.

👆
resize container »
300px
Viewport:Normal (>200px)
Mode:Draggable 👆
Defaults:ease=linear, duration=2000ms
Initializing...
// Similar to vanilla JS pattern:
createScope({
  mediaQueries: { isSmall: '(max-width: 200px)' },
  defaults: { ease: 'linear', duration: 2000 },
})
.add((self) => {
  const { isSmall } = self.matches;
  
  if (isSmall) {
    // Small viewport: Animate only
    animate(element, { rotate: 360, loop: true });
  } else {
    // Large viewport: Create draggable
    createDraggable(element, { container: root });
  }
  
  // Cleanup on scope revert
  return () => {
    element.classList.remove('draggable');
  };
});

basic scope

Create a scoped animation context with automatic cleanup. Only elements within the scope root are animated.

Scope initializing

root parameter

CSS selectors are scoped to the root element. Elements outside the scope are not affected.

Outside Scope (not animated)
Inside Scope (animated)
The same CSS selector .scoped-box is used in both containers, but only elements inside the scope root are animated.

shared defaults

Use scope defaults to share animation parameters like easing and duration across all animations.

rotate: 180°
scale: 1.2x
borderRadius: 50%
ease: outExpoduration: 800ms
Progress0%

Scope

Using useAnimeScope and useAnime hooks together. The animation automatically adapts when the container crosses 200px.

resize iframe »
300px
Size:Normal (>200px)
Direction:Horizontal ↔
Reduce Motion:Off

registered methods

Register methods within the scope that can be called externally via scope.methods

Console
// Click a method button...

addOnce method (Component)

Using AnimeScope component - register a constructor that runs only once via animateOnce prop, even when media queries change.

animate
animateOnce
animate runs:0
animateOnce runs:0
Restart to see both constructors run. Notice animate increments but animateOnce stays at 1.

keepTime method (Component)

Using AnimeScope component with ref to call keepTime() - preserve animation progress when refreshing the scope.

Before Refresh0%
->
After Refresh0%
Refreshes:0
Mode:Preserving time
With keepTime(), animation continues from current position after refresh.

refresh method (Component)

Using AnimeScope component with ref to call refresh() - re-run all constructors to pick up DOM changes.

Elements:3
Refreshes:0
Add or remove elements, then click Refresh to re-run constructors and pick up the DOM changes.

batch revert

Use revert() to clean up all animations in the scope at once. Cleanup functions are also called.

Status:idle
Active animations: 0
Click Start to create multiple animations, then Revert to clean them all up at once.

scope properties (Component)

Access scope properties via ref: root, matches, and methods. These provide context about the scope state.

scope.rootnull
The root element where CSS selectors are scoped
scope.matches0 queries
scope.methods0 methods
No methods registered
These properties are accessible from the scope ref. Click the method buttons to call registered methods.