### Using stagger start parameter with animate Source: https://github.com/aidan0x13/animejs-docs/blob/master/documentationstaggerstagger-parametersstagger-start.md Example showing how to set the `start` parameter for both the `x` stagger and the `delay` stagger. The `start` value is added to the staggered value, so with `start: 14` the first square's `x` becomes 14rem, and with `start: 500` the first delay becomes 500ms. ```javascript import { animate, stagger } from 'animejs'; animate('.square', { x: stagger('1rem', { start: 14 }), // adds 11 to the staggered value delay: stagger(100, { start: 500 }), // adds 500 to the staggered value }); ``` -------------------------------- ### HTML for onBegin example Source: https://github.com/aidan0x13/animejs-docs/blob/master/documentationtimertimer-callbacksonbegin.md HTML markup for displaying the status and current time in the onBegin example. ```html
      began
      false
    
      current time
      0
    
``` -------------------------------- ### HTML for then() example Source: https://github.com/aidan0x13/animejs-docs/blob/master/documentationanimationanimation-callbacksthen.md HTML structure for the then() example, including a circle and a log area to display the promise status. ```html
    promise status
    pending
  
``` -------------------------------- ### stagger start parameter Source: https://github.com/aidan0x13/animejs-docs/blob/master/documentationstaggerstagger-parametersstagger-start.md Example usage of the `start` parameter in the `stagger()` function to define the starting value of the stagger. ```APIDOC ## stagger start parameter ### Description Defines the starting value of the stagger. Accepts a number or a timeline time position (only when used as a timeline position argument). Default is 0. ### Method N/A (This is a parameter of the `stagger()` function) ### Endpoint N/A ### Parameters #### Parameter: start - **type**: Number | Timeline time position - **Default**: 0 - **Description**: The starting value of the stagger. ### Request Example ```javascript import { animate, stagger } from 'animejs'; animate('.square', { x: stagger('1rem', { start: 14 }), // adds 11 to the staggered value delay: stagger(100, { start: 500 }), // adds 500 to the staggered value }); ``` ### Response N/A ``` -------------------------------- ### Live example: waapi.animate with then() and promise status display Source: https://github.com/aidan0x13/animejs-docs/blob/master/documentationweb-animation-apiapi-differences-with-native-waapifinished.md Complete example with import, animation setup, and then() callback updating a value element. Includes the HTML structure for the promise status display. ```javascript import { waapi, utils } from 'animejs'; const [ $value ] = utils.$('.value'); const animation = waapi.animate('.circle', { translate: '16rem', loop: 2, alternate: true, }); animation.then(() => $value.textContent = 'fulfilled'); ``` ```html
    promise status
    pending
  
``` -------------------------------- ### HTML for loop example output Source: https://github.com/aidan0x13/animejs-docs/blob/master/documentationtimertimer-playback-settingsloop.md HTML markup for displaying the loop count and iteration time in the example. ```html
      loops count
      0
    
      iteration time
      0
    
``` -------------------------------- ### HTML for padStart animation example Source: https://github.com/aidan0x13/animejs-docs/blob/master/documentationutilitiespad-start.md HTML markup for the animation example, containing a div with class 'value' that displays the animated value. ```html
    0
  
``` -------------------------------- ### HTML markup for ease example rows Source: https://github.com/aidan0x13/animejs-docs/blob/master/documentationanimationtween-parametersease.md HTML structure for the example rows, showing labels for each easing configuration. ```html
all: 'inQuad'
all: eases.outQuad
x: createSpring()
rotate: 'inQuad'
``` -------------------------------- ### HTML for scope example Source: https://github.com/aidan0x13/animejs-docs/blob/master/documentationscope.md HTML markup for the scope example, containing a resizable iframe with a square element. ```html
``` -------------------------------- ### Full example with then() and DOM update Source: https://github.com/aidan0x13/animejs-docs/blob/master/documentationanimationanimation-callbacksthen.md Complete example showing an animation with a delay and a then() callback that updates a DOM element's text content. ```javascript import { animate } from 'animejs'; const [ $value ] = utils.$('.value'); const animation = animate('.circle', { x: '16rem', delay: 500, }); animation.then(() => $value.textContent = 'fulfilled'); ``` -------------------------------- ### HTML for onLoop example Source: https://github.com/aidan0x13/animejs-docs/blob/master/documentationanimationanimation-callbacksonloop.md Markup for the onLoop example, including a circle element and a log area to display the loop count. ```html
    loops
    0
  
``` -------------------------------- ### HTML markup for loop examples Source: https://github.com/aidan0x13/animejs-docs/blob/master/documentationanimationanimation-playback-settingsloop.md HTML structure for the loop examples, showing the elements with classes matching the animate targets. ```html
loop: 3
loop: 3, alternate: true
loop: 3, reversed: true
loop: true
``` -------------------------------- ### HTML markup for alternate() example Source: https://github.com/aidan0x13/animejs-docs/blob/master/documentationtimelinetimeline-methodsalternate.md Provides the HTML structure for the example, including a container with three animated elements and a button to trigger the alternate() method. ```html
``` -------------------------------- ### HTML structure for alternate example Source: https://github.com/aidan0x13/animejs-docs/blob/master/documentationtimelinetimeline-playback-settingsalternate.md Provides the HTML markup for the alternate example, including the animated elements and a log display for the loop counter. ```html
    loops
    0
  
``` -------------------------------- ### HTML for loopDelay example Source: https://github.com/aidan0x13/animejs-docs/blob/master/documentationanimationanimation-playback-settingsplayback-loopdelay.md Provides the HTML structure with a circle element used in the loopDelay animation example. ```html
``` -------------------------------- ### HTML for onRender example Source: https://github.com/aidan0x13/animejs-docs/blob/master/documentationanimationanimation-callbacksonrender.md HTML markup for the onRender example, containing a circle element and a log display for the render count. ```html
    renders
    0
  
``` -------------------------------- ### HTML for reverse timer example Source: https://github.com/aidan0x13/animejs-docs/blob/master/documentationtimertimer-methodsreverse.md HTML markup for the reverse timer example, including a display area for the iteration time and a button to trigger the reverse action. ```html
      iteration time
      0
    
``` -------------------------------- ### HTML markup for the seek() example Source: https://github.com/aidan0x13/animejs-docs/blob/master/documentationtimertimer-methodsseek.md Provides the HTML structure for the seek() example: a display area showing the current time, a range input (0-2000) for seeking, and a play/pause button. This markup is required for the JavaScript example to function. ```html
      current time
      0
    
``` -------------------------------- ### HTML for wrap() animation example Source: https://github.com/aidan0x13/animejs-docs/blob/master/documentationutilitieswrap.md The HTML markup for the animation example, containing two clock divs with labels. ```html
normal
wrapped [-.25,.25]
``` -------------------------------- ### HTML markup for sync() example Source: https://github.com/aidan0x13/animejs-docs/blob/master/documentationtimelinesync-waapi-animations.md HTML structure used in the sync() example, containing three elements (triangle, square, circle) inside a pyramid container. ```html
``` -------------------------------- ### HTML structure for the add() example Source: https://github.com/aidan0x13/animejs-docs/blob/master/documentationtimelinetimeline-methodsadd.md The HTML markup that accompanies the add() example, containing a circle element and a log area with a value display. ```html
    value
    0
  
``` -------------------------------- ### HTML for round() example Source: https://github.com/aidan0x13/animejs-docs/blob/master/documentationutilitiesround.md HTML markup for the round() example, containing two columns with clock elements and labels 'normal' and 'rounded (.1)'. ```html
normal
rounded (.1)
``` -------------------------------- ### HTML for onLoop example Source: https://github.com/aidan0x13/animejs-docs/blob/master/documentationtimertimer-callbacksonloop.md HTML markup for displaying the loop count and iteration time in the onLoop example. It includes two log rows with labels and value spans. ```html
      loops
      0
    
      iteration time
      0
    
``` -------------------------------- ### HTML markup for color() animation example Source: https://github.com/aidan0x13/animejs-docs/blob/master/documentationanimationtween-value-typescolor-function-value.md Provides the HTML structure with six circle elements used in the color() animation example. ```html
``` -------------------------------- ### HTML: Markup for refresh() example Source: https://github.com/aidan0x13/animejs-docs/blob/master/documentationtimelinetimeline-methodsrefresh.md Provides the HTML structure for the refresh() example: a container with triangle, square, and circle elements, and a button to trigger the refresh and restart. ```html
``` -------------------------------- ### HTML markup for alternate examples Source: https://github.com/aidan0x13/animejs-docs/blob/master/documentationanimationanimation-playback-settingsalternate.md HTML structure for the three animation examples, each with a circle element and a label indicating the `alternate` and `reversed` settings. ```html
alternate: false
alternate: true
alternate: true, reversed: true
``` -------------------------------- ### HTML markup for onLoop example Source: https://github.com/aidan0x13/animejs-docs/blob/master/documentationtimelinetimeline-callbacksonloop.md HTML structure for the onLoop example, including a container with triangle, square, and circle elements, and a log area with a label and value span. ```html
    loops
    0
  
``` -------------------------------- ### HTML markup for onUpdate example Source: https://github.com/aidan0x13/animejs-docs/blob/master/documentationtimertimer-callbacksonupdate.md HTML structure for displaying the updates count and current time in the onUpdate example. Uses pre and span elements with classes for styling. ```html
      updates
      0
    
      current time
      0
    
``` -------------------------------- ### Interactive precision control example Source: https://github.com/aidan0x13/animejs-docs/blob/master/documentationengineengine-parametersprecision.md Creates 150 animated particles and updates engine.precision based on a range input. This example shows how to use engine.precision with a slider to adjust rounding in real-time. ```javascript import { engine, animate, utils } from 'animejs'; const [ $container ] = utils.$('.container'); const [ $range ] = utils.$('.range'); for (let i = 0; i < 150; i++) { const $particle = document.createElement('div'); $particle.classList.add('particle'); $container.appendChild($particle); animate($particle, { x: utils.random(-10, 10, 2) + 'rem', y: utils.random(-3, 3, 2) + 'rem', scale: [{ from: 0, to: 1 }, { to: 0 }], delay: utils.random(0, 1000), loop: true, }); } function onInput() { engine.precision = this.value; } $range.addEventListener('input', onInput); ``` ```html
``` -------------------------------- ### HTML for pauseOnDocumentHidden toggle example Source: https://github.com/aidan0x13/animejs-docs/blob/master/documentationengineengine-parameterspauseondocumenthidden.md HTML markup for the interactive example: displays global time and engine time, and provides a toggle button to switch the pauseOnDocumentHidden setting. ```html
      global time
      0
    
      engine time
      0
    
``` -------------------------------- ### HTML: Markup for reverse button example Source: https://github.com/aidan0x13/animejs-docs/blob/master/documentationtimelinetimeline-methodsreverse.md Provides the HTML structure for the reverse example, including a container with triangle, square, and circle elements, and a button with class 'reverse' that triggers the timeline reversal. ```html
``` -------------------------------- ### Live demo: lerp with animate and createTimer Source: https://github.com/aidan0x13/animejs-docs/blob/master/documentationutilitieslerp.md Complete example from the documentation showing how to use utils.lerp() in a live demo with animate, createTimer, and utils methods. Includes JavaScript and HTML for the demo. ```javascript import { animate, createTimer, utils } from 'animejs'; const [ $input ] = utils.$('.input'); const [ $lerped ] = utils.$('.lerped'); const [ $lerped15fps ] = utils.$('.lerped-15'); animate($input, { rotate: '1000turn', modifier: utils.snap(.25), duration: 4000000, loop: true, ease: 'linear', }); const loop = createTimer({ onUpdate: clock => { const sourceRotate = utils.get($input, 'rotate', false); const lerpedRotate = utils.get($lerped, 'rotate', false); utils.set($lerped, { rotate: utils.lerp(lerpedRotate, sourceRotate, .075) + 'turn' }); } }); const loop15fps = createTimer({ frameRate: 15, onUpdate: clock => { const sourceRotate = utils.get($input, 'rotate', false); const lerpedRotate = utils.get($lerped15fps, 'rotate', false); utils.set($lerped15fps, { rotate: utils.lerp(lerpedRotate, sourceRotate, .0725, clock) + 'turn' }); } }); ``` ```html
input
lerped
lerped 15fps
``` -------------------------------- ### Timeline time position example with labels and relative positions Source: https://github.com/aidan0x13/animejs-docs/blob/master/documentationtimelinetime-position.md Creates a timeline with a label at 0ms, adds three animations at different positions: absolute 500ms, label 'start', and relative '<-=250'. The example uses createTimeline from animejs. ```javascript import { createTimeline } from 'animejs'; const tl = createTimeline() .label('start', 0) .add('.square', { x: '15rem', duration: 500, }, 500) .add('.circle', { x: '15rem', duration: 500, }, 'start') .add('.triangle', { x: '15rem', rotate: '1turn', duration: 500, }, '<-=250'); ``` -------------------------------- ### utils.padStart(totalLength, padString) Source: https://github.com/aidan0x13/animejs-docs/blob/master/documentationutilitiespad-start.md Creates a chain-able utility Function to pad numbers from the start with pre-defined totalLength and padString parameters. ```APIDOC ## utils.padStart(totalLength, padString) ### Description Creates a chain-able utility Function to pad numbers from the start with pre-defined totalLength and padString parameters. ### Method Function call ### Endpoint `utils.padStart(totalLength, padString)` ### Parameters - **totalLength** (Number) - Required - The desired length of the padded string. - **padString** (String) - Required - The string to pad with. ### Returns A chain-able utility Function to pad numbers from the start. ### Example ```js const padTo5WithZeros = utils.padStart(5, '0'); padTo5WithZeros('123'); // '00123' padTo5WithZeros(78); // '00078' padTo5WithZeros('1234'); // '01234' const roundAndPad = utils.round(2).padStart(5, '0'); // Round to 2 decimal places then pad to 5 characters roundAndPad(12.345); // '12.35' roundAndPad(7.8); // '07.80' ``` ``` -------------------------------- ### stagger() with grid parameter Source: https://github.com/aidan0x13/animejs-docs/blob/master/documentationstaggerstagger-parametersstagger-grid.md Example of using the stagger() function with the grid parameter to animate elements in a grid layout with a random starting point. ```APIDOC ## stagger() with grid parameter ### Description Distributes stagger values on a 2D array using the grid parameter. ### Method stagger() ### Parameters #### grid - **grid** (Array) - Required - An array of two numbers [columns, rows] defining the grid dimensions. ### Example ```javascript import { animate, stagger } from 'animejs'; const $squares = utils.$('.square'); function animateGrid() { animate($squares, { scale: [ { to: [0, 1.25] }, { to: 0 } ], boxShadow: [ { to: '0 0 1rem 0 currentColor' }, { to: '0 0 0rem 0 currentColor' } ], delay: stagger(100, { grid: [11, 4], from: utils.random(0, 11 * 4) }), onComplete: animateGrid }); } animateGrid(); ``` ``` -------------------------------- ### Compare WAAPI and JS animations with CPU blocking Source: https://github.com/aidan0x13/animejs-docs/blob/master/documentationweb-animation-apihardware-accelerated-animations.md Demonstrates hardware-accelerated WAAPI animations versus JS-driven animations. The WAAPI example uses the 'cubicBezier' easing, while the JS example uses 'x' instead of 'translate'. The setup includes a CPU-blocking timer to show the performance difference. Note that Safari may not hardware-accelerate animations using custom 'linear()' easing or JavaScript eases. ```javascript import { animate, waapi, createTimer, utils } from 'animejs'; const [ $block ] = utils.$('.button'); const waapiAnim = waapi.animate('.waapi.square', { translate: 270, rotate: 180, alternate: true, loop: true, ease: 'cubicBezier(0, 0, .58, 1)', }); const jsAnim = animate('.js.square', { x: 270, rotate: 180, ease: 'cubicBezier(0, 0, .58, 1)', alternate: true, loop: true, }); const blockCPUTimer = createTimer({ onUpdate: () => { const end = Date.now() + 100; while(Date.now() < end) { Math.random() * Math.random(); } }, autoplay: false }); let isBusy = false; const toggleCPU = () => { blockCPUTimer[isBusy ? 'pause' : 'play'](); $block.innerText = (isBusy ? 'block' : 'free') + ' CPU'; isBusy = !isBusy; } $block.addEventListener('click', toggleCPU); ``` ```html
WAAPI
JS
``` -------------------------------- ### Create timeline with cancel() and play() buttons Source: https://github.com/aidan0x13/animejs-docs/blob/master/documentationtimelinetimeline-methodscancel.md Setup for the 4.0.0+ cancel() example. Creates a looping timeline with alternate direction, adds motion to .circle, .triangle, and .square elements, and wires Cancel/Play buttons to tl.cancel() and tl.play(). ```javascript import { createTimeline, utils } from 'animejs'; const [ $cancelButton ] = utils.$('.cancel'); const [ $playButton ] = utils.$('.play'); const tl = createTimeline({ loop: true, alternate: true, }) .add('.circle', { x: '15rem' }) .add('.triangle', { x: '15rem' }, 500) .add('.square', { x: '15rem' }, 1000); const cancelTimeline = () => tl.cancel(); const playTimeline = () => tl.play(); $cancelButton.addEventListener('click', cancelTimeline); $playButton.addEventListener('click', playTimeline); ``` ```html
``` -------------------------------- ### Full example with pause/resume buttons Source: https://github.com/aidan0x13/animejs-docs/blob/master/documentationengineengine-methodsresume.md Creates 150 animated particles and wires pause/resume buttons to engine.pause() and engine.resume(). Includes the required HTML structure. ```javascript import { engine, animate, utils } from 'animejs'; const [ $container ] = utils.$('.container'); const [ $pause, $resume ] = utils.$('button'); function addAnimation() { const $particle = document.createElement('div'); $particle.classList.add('particle'); $container.appendChild($particle); animate($particle, { x: utils.random(-10, 10, 2) + 'rem', y: utils.random(-3, 3, 2) + 'rem', scale: [{ from: 0, to: 1 }, { to: 0 }], loop: true, delay: utils.random(0, 1000) }); } for (let i = 0; i < 150; i++) addAnimation(); const resumeEngine = () => engine.resume(); const pauseEngine = () => engine.pause(); $pause.addEventListener('click', pauseEngine); $resume.addEventListener('click', resumeEngine); ``` ```html
``` -------------------------------- ### play() method example with autoplay disabled Source: https://github.com/aidan0x13/animejs-docs/blob/master/documentationanimationanimation-methodsplay.md Creates an animation with autoplay disabled, then plays it on a button click. The animation moves .square elements horizontally by 17rem with an inOutSine easing and staggered delay of 100ms. The play() method is called on the animation instance to start it. ```javascript import { animate, utils, stagger } from 'animejs'; const [ $playButton ] = utils.$('.play'); const animation = animate('.square', { x: '17rem', ease: 'inOutSine', delay: stagger(100), autoplay: false, // The animation is paused by default }); const playAnimation = () => animation.play(); $playButton.addEventListener('click', playAnimation); ``` ```html
``` -------------------------------- ### Full Example: Registering onClick Method with Scope Source: https://github.com/aidan0x13/animejs-docs/blob/master/documentationscoperegister-method-function.md Complete example from the documentation. Creates a scope with a media query, registers an 'onClick' method that animates a square based on click position and screen size, and attaches the method to a document click listener outside the scope. ```javascript import { utils, animate, createScope } from 'animejs'; const scope = createScope({ mediaQueries: { isSmall: '(max-width: 200px)' }, }) .add(self => { /* Registering the method inside the scope allows access to the scope itself */ self.add('onClick', (e) => { const { clientX, clientY } = e; const { isSmall } = self.matches; animate('.square', { rotate: isSmall ? '+=360' : 0, x: isSmall ? 0 : clientX - (window.innerWidth / 2), y: isSmall ? 0 : clientY - (window.innerHeight / 2), duration: isSmall ? 750 : 400, }); }); utils.set(document.body, { cursor: self.matches.isSmall ? 'alias' : 'crosshair' }); }); /* Methods can be called outside the scope */ document.addEventListener('click', scope.methods.onClick); ``` -------------------------------- ### HTML for waapi.animate example Source: https://github.com/aidan0x13/animejs-docs/blob/master/documentationweb-animation-apiimprovements-to-the-web-animation-apisensible-defaults.md HTML markup for the circle element used in the waapi.animate example. ```html
``` -------------------------------- ### HTML structure for scroll example Source: https://github.com/aidan0x13/animejs-docs/blob/master/documentationscroll.md HTML structure for the scroll example. It defines a scroll container with sections for the animation target, the timer display, and the timeline circles. The timer value is updated by the JavaScript example. ```html
scroll down
          timer
          0
        
``` -------------------------------- ### HTML markup for WAAPI animation example Source: https://github.com/aidan0x13/animejs-docs/blob/master/documentationweb-animation-api.md HTML structure with spans that are animated by the WAAPI example. ```html

H E L L O   W A A P I

``` -------------------------------- ### Full animate example with percentage-based keyframes Source: https://github.com/aidan0x13/animejs-docs/blob/master/documentationanimationkeyframespercentage-based-keyframes.md Complete example using the animate function with percentage-based keyframes. The ease parameter can be set per keyframe, and the global ease and playbackEase options control easing between and across keyframes. Includes a corresponding HTML element. ```javascript import { animate } from 'animejs'; animate('.square', { keyframes: { '0%' : { x: '0rem', y: '0rem', ease: 'out' }, '13%' : { x: '0rem', y: '-2.5rem', }, '37%' : { x: '17rem', y: '-2.5rem', scale: .5 }, '63%' : { x: '17rem', y: '2.5rem', scale: .5 }, '87%' : { x: '0rem', y: '2.5rem', scale: 1 }, '100%': { y: '0rem', ease: 'in' } }, rotate: { to: 360, ease: 'linear' }, duration: 3000, ease: 'inOut', // ease applied between each keyframes if no ease defined playbackEase: 'ouIn(5)', // ease applied accross all keyframes loop: true, }); ``` ```html
``` -------------------------------- ### HTML for modifier examples Source: https://github.com/aidan0x13/animejs-docs/blob/master/documentationanimationtween-parametersmodifier.md The HTML markup for the three rows of squares used in the modifier examples. ```html
utils.round(0)
v => v % 17
v => Math.cos(v) / 2
``` -------------------------------- ### utils.padStart(value, totalLength, padString) Source: https://github.com/aidan0x13/animejs-docs/blob/master/documentationutilitiespad-start.md Pads a number from the start with a string until the result reaches a given length. Returns a string. ```APIDOC ## utils.padStart(value, totalLength, padString) ### Description Pads a Number from the start with a string until the result reaches a given length. ### Method Function call ### Endpoint `utils.padStart(value, totalLength, padString)` ### Parameters - **value** (String / Number) - Optional - The value to pad. - **totalLength** (Number) - Required - The desired length of the padded string. - **padString** (String) - Required - The string to pad with. ### Returns A String if a value is provided. ### Example ```js const paddedValue = utils.padStart(value, totalLength, padString); ``` ``` -------------------------------- ### Interactive shuffle example with animation Source: https://github.com/aidan0x13/animejs-docs/blob/master/documentationutilitiesshuffle.md Complete example that shuffles squares and animates their x position on button click. Requires the HTML structure with squares and a button. Uses utils.$ to select elements and animate to trigger the animation. ```javascript import { utils } from 'animejs'; const [ $shuffle ] = utils.$('button'); const squares = utils.$('.square'); const x = stagger('3.2rem'); // Initial squares x position utils.set(squares, { x }); const shuffle = () => animate(utils.shuffle(squares), { x }); $shuffle.addEventListener('click', shuffle); ``` ```html
A
B
C
D
E
F
``` -------------------------------- ### Ease usage example with animate, waapi, and createSpring Source: https://github.com/aidan0x13/animejs-docs/blob/master/documentationanimationtween-parametersease.md Demonstrates using ease as a string, as a function from eases, per-property easing, and createSpring with waapi.animate. ```javascript import { animate, waapi, eases, createSpring } from 'animejs'; animate('.row:nth-child(1) .square', { x: '17rem', rotate: 360, ease: 'inQuad', }); animate('.row:nth-child(2) .square', { x: '17rem', rotate: 360, ease: eases.outQuad, }); waapi.animate('.row:nth-child(3) .square', { x: '17rem', rotate: { to: 360, ease: 'out(6)', }, ease: createSpring({ stiffness: 70 }), }); ``` -------------------------------- ### HTML markup for delay example Source: https://github.com/aidan0x13/animejs-docs/blob/master/documentationanimationanimation-playback-settingsdelay.md HTML structure for the delay example, containing a circle element with class 'delay'. ```html
``` -------------------------------- ### HTML for duration examples Source: https://github.com/aidan0x13/animejs-docs/blob/master/documentationanimationanimation-playback-settingsduration.md HTML markup for the duration examples, containing circles with classes `dur-0`, `dur-500`, and `dur-2000` and labels. ```html
duration: 0
duration: 500
duration: 2000
``` -------------------------------- ### animate() with callbacks Source: https://github.com/aidan0x13/animejs-docs/blob/master/documentationanimationanimation-callbacks.md Example of specifying callbacks (onBegin, onLoop, onUpdate) directly in the animate() parameters object. The animation includes translateX, scale, opacity, duration, delay, ease, loop, alternate, and autoplay settings. ```javascript animate('.square', { translateX: 100, scale: 2, opacity: .5, duration: 400, delay: 250, ease: 'out(3)', loop: 3, alternate: true, autoplay: false, ┌─────────────────────┐ │ onBegin: () => {}, │ │ onLoop: () => {}, ├─ Callbacks │ onUpdate: () => {}, │ └─────────────────────┘ }); ``` -------------------------------- ### HTML structure for remove() example Source: https://github.com/aidan0x13/animejs-docs/blob/master/documentationutilitiesremove.md The HTML markup used in the remove() example, including the squares, the log display, and the control buttons. ```html
  updates
  --
``` -------------------------------- ### createTimer with loop setting Source: https://github.com/aidan0x13/animejs-docs/blob/master/documentationtimertimer-playback-settingsloop.md Example of creating a timer with the loop playback setting set to true, demonstrating the onLoop and onUpdate callbacks. ```APIDOC ## createTimer ### Description Creates a timer with the specified playback settings, including the loop property that defines how many times the timer repeats. ### Method createTimer ### Parameters #### Options Object - **loop** (Number | Infinity | true | -1) - Optional - Defines how many times the timer repeats. Accepts a number in the range [0, Infinity], Infinity, true (equivalent to Infinity), or -1 (equivalent to Infinity). Default is 0. - **duration** (Number) - Optional - The duration of each loop iteration in milliseconds. - **onLoop** (Function) - Optional - Callback function invoked each time the timer loops. - **onUpdate** (Function) - Optional - Callback function invoked on each update, receiving the timer instance as an argument. ### Request Example ```javascript import { createTimer, utils } from 'animejs'; const [ $loops ] = utils.$('.loops'); const [ $time ] = utils.$('.time'); let loops = 0; createTimer({ loop: true, duration: 1000, onLoop: () => $loops.innerHTML = ++loops, onUpdate: self => $time.innerHTML = self.iterationCurrentTime }); ``` ### Response #### Success Response No explicit response is documented. The timer runs asynchronously and invokes the provided callbacks. ### Notes - The default value of `loop` is `0`. - To change the default value globally, update the `engine.defaults` object: ```javascript import { engine } from 'animejs'; engine.defaults.loop = true; ``` ``` -------------------------------- ### then() callback example Source: https://github.com/aidan0x13/animejs-docs/blob/master/documentationtimelinetimeline-callbacksthen.md Full example showing then() with a callback that updates the DOM when the timeline fulfills. The timeline loops once and has a default duration of 500ms. ```javascript import { createTimeline, utils } from 'animejs'; const [ $value ] = utils.$('.value'); const tl = createTimeline({ defaults: { duration: 500 }, loop: 1, }) .add('.circle', { x: '15rem' }) .add('.triangle', { x: '15rem' }) .add('.square', { x: '15rem' }); tl.then(() => $value.textContent = 'fulfilled'); ``` -------------------------------- ### Resume, pause, and alternate timer methods Source: https://github.com/aidan0x13/animejs-docs/blob/master/documentationtimertimer-methodsresume.md Example showing how to create a timer and control it with resume(), pause(), and alternate() methods. The timer updates the displayed iteration time and loops. The HTML provides buttons to trigger these methods. ```javascript import { createTimer, utils } from 'animejs'; const [ $resumeButton, $pauseButton, $alternateButton ] = utils.$('.button'); const [ $time ] = utils.$('.time'); const timer = createTimer({ duration: 2000, onUpdate: self => $time.innerHTML = self.iterationCurrentTime, loop: true, }); const resumeTimer = () => timer.resume(); const pauseTimer = () => timer.pause(); const alternateTimer = () => timer.alternate(); $resumeButton.addEventListener('click', resumeTimer); $pauseButton.addEventListener('click', pauseTimer); $alternateButton.addEventListener('click', alternateTimer); ``` ```html
      iteration time
      0
    
``` -------------------------------- ### HTML markup for stagger range example Source: https://github.com/aidan0x13/animejs-docs/blob/master/documentationstaggerstagger-value-typesrange-value.md HTML structure with a container and multiple square elements used in the stagger range example. ```html
```