Lottielab Docs
  • Getting Started
    • Welcome to Lottielab
    • Tutorials
    • Templates and Examples
    • Design vs Animate mode
    • Keyboard Shortcuts
    • FAQ
  • File management
    • Dashboard UI Overview
    • Files
      • Create a file
      • Import a file
      • Duplicate a file
      • Export a file
      • Move a file
      • Share link to file
      • Rename a file
    • Teams
      • Create a team
      • Invite team members
      • Rename a team
    • Folders
      • Create a folder
      • Rename a folder
      • Delete a folder
  • Editor
    • Editor UI Overview
    • Tools
      • Selection Tools
      • Shape Tools
      • Pen tool and paths
        • Create a path
        • Curve a path
        • Add a point on a path
        • Delete a point on a path
        • Convert shape to path
      • Import
      • Layer mask
    • Animating
      • Design vs Animate mode
      • Auto-animate
      • Timeline
        • Duration and playback
        • Playhead and controls
        • Keyframes
          • Add a keyframe
          • Duplicate keyframes
          • Keyframe thumbnails
        • Transition bar
        • Layers and properties
      • Easing
        • Add easing
        • Custom easing
          • Speed Graph
          • Anticipation
          • Overshoot
        • Easing presets
    • Organising Layers
      • Layer actions
        • Select/ Multi-select layers
        • Rename a layer
        • Align layers on canvas
        • Re-order layers
        • Delete a layer
        • Hide a layer
        • Lock a layer
      • Groups
        • Grouping layers
        • Ungroup layers
    • Properties
      • Transform
        • Position
        • Scale
        • Size/ Dimensions
        • Rotation
        • Skew
        • Anchor Point (Origin)
        • Corner Radius
      • Visibility
      • Fill/ Color
        • Add/ change fill color
        • Gradient
          • Linear gradient
          • Radial gradient
          • Gradient stops
          • Gradient handles (width and direction)
        • Eye dropper
        • Fill Opacity
        • Document colors
        • Color model
      • Stroke
      • Reveal Path (Trim path)
    • Canvas
      • Infinite Canvas/ Multiple Artboards
      • Artboard properties
      • Layer controls (HUDs)
        • Layer transform controls
        • Motion Path
          • Create a motion path
          • Curving a motion path
          • Motion path easing
      • Zoom
      • Animation Duration
    • Interactivity
      • Intro to Interactivity
      • States
      • Interactions
      • Formulas
      • Using Interactive Lotties
  • Export & Hand-off
    • Comments
    • Share link to file
    • Livelink (CDN)
      • Optimisation
      • Customising embed links
    • Code Export Platforms
      • Web
        • JavaScript (Vanilla)
        • React JS
        • Angular
        • Vue JS
        • Webflow
        • Framer
        • Wordpress
      • Mobile
        • iOS
        • Android
        • React Native
    • File download
      • Lottie JSON download
      • GIF download
      • MP4 download
Powered by GitBook
On this page
  • Formula language
  • Types
  • Operators
  • Built-in functions and constants
  • Built-in variables
  • Custom variables

Was this helpful?

  1. Editor
  2. Interactivity

Formulas

Reference manual for the advanced Custom formula feature.

PreviousInteractionsNextUsing Interactive Lotties

Last updated 9 months ago

Was this helpful?

When choosing an , one of the options is a Custom formula. This allows you to create a that uses the full power of the scripting engine in Lottielab Interactivity.

With a custom formula mapping, you get a text field where you can type in a formula whose result will be used to control the selected parameter (playhead position, blending with another state, or playback speed):

These formulas use a simple expression language. At each frame, the value of the expression is calculated, and the output (typically 0-1) is applied to the selected parameter:

  • For the "Time (progress)" mapping, 0 means the beginning of the state's segment, and 1 means the end of the state's segment (with intermediate values in-between.)

  • For the "Playback speed" mapping, the value is directly applied as a speed coefficient (1.0 = normal speed, 0.5 = twice as slow, etc.)

  • For the "Blend" mapping, the value is applied as the blending coefficient between this state and the other selected state (0.0 = fully display this state, 1.0 = fully display the other state, 0.5 = blend 50/50 between the states, etc.).

Lottielab Player also exposes several built-in variables based on user input, and allows you to provide custom variables that can be re-used from the formula.

Formula language

The formula language follows the expression rules of a C-like language. You can use parentheses and specify literal numbers.

Types

All types are floating point numbers. For the purposes of boolean operations, all non-0 numbers are interpreted as truthy (and 0 numbers as falsy).

Operators

These operators are available, from highest to lowest precedence:

  • Logical negation (!)

  • Exponent/power operation (^)

  • Multiplication and division (*, /)

  • Addition and subtraction (+, -)

  • Comparisons (>, <, >=, <=, ==)

  • Logical (||, &&)

  • Ternary conditional (?:, as in condition ? a : b)

Built-in functions and constants

Built-in variables

The Lottielab Player runtime provides several variables that can be used in the formula to respond to user input:

  • time: Time in seconds since this state started.

  • time.abs: Time in seconds since the animation first started.

  • playhead: The current playhead position in this state, in seconds.

  • playhead.progress: The current playhead position in this state, as a

  • value from 0 to 1 within the segment (0 = start, 1 = end).

  • playhead.abs: Global position of the playhead in seconds.

  • mouse.x, mouse.y: The current mouse position, relative to the top-left

  • of the lottie, in pixels

  • mouse.progress.x, mouse.progress.y: The current mouse position, as a value from 0 to 1 within the lottie's bounds (0 = left/top, 1 = right/bottom)

  • mouse.abs.x, mouse.abs.y: The current mouse position, relative to the top-left of the whole viewport rather than the lottie itself

  • mouse.buttons.left, mouse.buttons.right, mouse.buttons.middle: Whether the left, right, or middle mouse buttons are currently pressed

Custom variables

Note that, when using custom variables, the Lottielab preview page won't work properly, as it doesn't have a value for this variable. For testing purposes, you can temporarily change the variable name to something like mouse.progress.x in order to be able to test the interaction, and then change it back to your custom variable name before export.

The language provides support for This includes trigonometric functions, constants such as PI, logarithms, and others. These functions and constants are available without the `Math.` prefix. For example, a valid formula can be: sin(PI * mouse.progress.x).

You can use a variable name that doesn't appear in the list above. In this case, the variable is treated as a custom variable, and you should provide the value at runtime using the interactivity.inputs.set() .

all functions and constants inside the JavaScript Math namespace.
API of the Lottielab player
interaction type
mapping
Custom formula UI