Advanced

Scope

The Scope API lets you create responsive animations that react to media queries, keeping animations clean and isolated within a root element.

createScope()

import { createScope, animate, createTimeline } from 'animejs';

createScope({
  root: '#app',
  mediaQueries: {
    portrait: '(orientation: portrait)',
    large: '(min-width: 1024px)',
  }
}).add(({ matches }) => {
  const isPortrait = matches.portrait;
  animate('.hero', {
    x: isPortrait ? 0 : [-50, 0],
    y: isPortrait ? [-30, 0] : 0,
    duration: 800,
    loop: true,
  });
});

Key Features

Options

PropertyDefaultDescription
rootdocumentRoot element to scope selectors to
mediaQueries{}Named media query object
defaults{}Default animation parameters for this scope

Methods