ThorVG WebCanvas API - v1.1.4
    Preparing search index...

    Class Animation

    Animation controller for Lottie animations The Animation owns a Picture internally and manages frame updates

    // Loading and playing a Lottie animation
    const animation = new TVG.Animation();

    fetch('/animations/loader.json')
    .then(res => res.text())
    .then(lottieData => {
    animation.load(lottieData);
    const picture = animation.picture();

    // Center and scale animation
    const size = picture.size();
    picture.translate(400 - size.width / 2, 300 - size.height / 2);

    canvas.add(picture);
    animation.play();
    });
    // Controlling animation playback
    const animation = new TVG.Animation();
    animation.load(lottieData);

    const info = animation.getInfo();
    console.log(`Duration: ${info.duration}s, FPS: ${info.fps}`);

    // Play with custom loop and speed
    animation.loop(true).play();

    // Pause after 2 seconds
    setTimeout(() => animation.pause(), 2000);

    // Jump to specific frame
    animation.frame(30).render();
    // Animation segments and callbacks
    const animation = new TVG.Animation();
    animation.load(lottieData);

    // Play specific segment
    animation.segment(0, 60);

    // Listen to frame updates
    animation.play((frame) => {
    console.log(`Current frame: ${frame}`);
    });

    LottieAnimation for Lottie advanced features

    Hierarchy (View Summary)

    Index
    • get picture(): Picture | null

      Get the Picture object that contains the animation content The Picture is owned by the Animation and should not be manually disposed

      Returns Picture | null

    • get ptr(): number

      Gets the WASM pointer for this object Returns 0 if object has been disposed (error handled by global handler)

      Returns number

    • get isDisposed(): boolean

      Check if this object has been disposed

      Returns boolean

    • Cleanup function to be implemented by subclasses

      Parameters

      • ptr: number

        The WASM pointer to clean up

      Returns void

    • Load Lottie animation from raw data

      Parameters

      • data: string | Uint8Array<ArrayBufferLike>

        Lottie JSON data as Uint8Array or string

      Returns this

    • Get or set the current frame

      Returns number

    • Get or set the current frame

      Parameters

      • frameNumber: number

      Returns this

    • Set the playback segment (for partial playback)

      Parameters

      • begin: number

        Segment begin frame

      • end: number

        Segment end frame

      Returns this

    • Play the animation

      Parameters

      • OptionalonFrame: (frame: number) => void

        Optional callback called on each frame update

      Returns this

    • Check if animation is currently playing

      Returns boolean

    • Set whether animation should loop

      Parameters

      • loop: boolean

      Returns this

    • Seek to a specific time (in seconds)

      Parameters

      • time: number

      Returns this