LiveAnimate

Declarative UI animations for Phoenix LiveView — entrance/exit, gestures, springs, and page transitions, straight from HEEx with (almost) no JavaScript.

Add one <.motion> component to your HEEx and get entrance/exit animations, hover/tap/drag gestures, spring physics, scroll triggers, layout (FLIP) animations, and server-driven page transitions. Animations run on the browser's Web Animations API for GPU-accelerated performance; the Elixir side stays purely declarative.

<.motion id="hero" animate="slide-up" hover="lift">
<h1>Hello, world!</h1>
</.motion>

Why LiveAnimate

Compared to JS.transition

Phoenix ships Phoenix.LiveView.JS.transition, which toggles CSS classes — you hand-write the keyframes and CSS yourself, and there's no spring physics, gestures, drag, FLIP layout, or page transitions. LiveAnimate gives you all of that declaratively, so most UI motion becomes a preset name instead of a stylesheet plus a JS command.

Installation

1. Add the dependency

# mix.exs
def deps do
[
{:live_animate, "~> 0.1.0"}
]
end

2. Set up JavaScript

// assets/js/app.js
import LiveAnimate from "live_animate"
let liveSocket = new LiveSocket("/live", Socket, {
...LiveAnimate.config(),
hooks: { ...LiveAnimate.hooks },
params: { _csrf_token: csrfToken }
})
LiveAnimate.init()

3. Import CSS

/* assets/css/app.css */
@import "../../deps/live_animate/assets/css/live_animate.css";

4. Import the component

# lib/my_app_web.ex
defp html_helpers do
quote do
import LiveAnimate
# ...
end
end

Quick start

<%# Fade in on mount %>
<.motion id="hero" animate="fade">
<h1>Hello, world!</h1>
</.motion>
<%# Hover and tap interactions %>
<.motion id="btn" hover="scale-up" tap="press">
<button>Click me</button>
</.motion>
<%# Exit animation %>
<.motion id="toast" animate="slide-left" exit="fade">
<p>Dismissible toast</p>
</.motion>

Available presets

Preset Type Description
fade entrance/exit Opacity 0 to 1
blur entrance/exit Opacity + blur
slide-up entrance/exit Translate Y + fade
slide-down entrance/exit Translate Y + fade
slide-left entrance/exit Translate X + fade
slide-right entrance/exit Translate X + fade
zoom-in entrance/exit Scale 0.8 to 1 + fade
zoom-out entrance/exit Scale 1.2 to 1 + fade
drop entrance/exit Translate Y + scale + fade
flip-x entrance/exit Rotate X 90deg + fade
flip-y entrance/exit Rotate Y 90deg + fade
scale-up gesture Scale to 1.05
scale-down gesture Scale to 0.95
press gesture Scale to 0.92
lift gesture Scale + drop shadow
tilt-left gesture Rotate -3deg
tilt-right gesture Rotate 3deg
shake keyframe Horizontal shake
bounce keyframe Vertical bounce
pulse keyframe Scale pulse
wiggle keyframe Rotational wiggle
spin keyframe Full 360deg rotation
ping keyframe Scale up + fade out
rubber-band keyframe Elastic stretch
float keyframe Gentle vertical bob (pair with loop: true)
highlight keyframe Non-displacing attention pulse (ring + tint)

Browser support

Documentation

Full documentation is available on HexDocs.

License

MIT - see LICENSE.