Skip to content

module

motion

GSAP-style animation in the browser, driven by weft_motion.

use weft::web::motion::{self, Vars, Stagger};
motion::to(".card", Vars::new().set("y", -8).set("rotation", 2).duration(0.6).ease("back.out(2)"));
motion::timeline()
    .from("h1", Vars::new().set("opacity", 0).set("y", 40), "")
    .from(".feature", Vars::new().set("opacity", 0).stagger(Stagger::each(0.08)), "-=0.3")
    .play();
motion::to(".hero img", Vars::new().set("scale", 1.2).scroll(motion::Scroll::new(".hero").scrub(1.0)));

Templates can animate declaratively with motion* attributes (see weft_motion::MotionSpec); the DOM host binds them after each render.

Structs

  • Animation

    A running (or paused) tween or timeline.

  • Scroll

    A scroll trigger for a tween or timeline.

  • TimelineBuilder

    A sequence of tweens.

  • Vars

    Tween settings and properties, GSAP's vars.

Enums

Functions

bind_declarative

pub fn bind_declarative(root: &Element)

Bind every declarative motion* animation under root, rebuilding any whose attributes changed. Called by the DOM host after each render.

bind_horizontal

pub fn bind_horizontal(root: &Element)

Drive [data-hscroll] sections (HorizontalScroll): the viewport sticks while the page scrolls past, and the track slides sideways by the same distance. Without the runtime (or with reduced motion) the track simply scrolls horizontally.

count

pub fn count() -> usize

How many animations are registered.

from

pub fn from(targets: impl Into<Targets>, vars: Vars) -> Animation

Animate from vars to the current values.

from_to

pub fn from_to(targets: impl Into<Targets>, from: Vars, to: Vars) -> Animation

Animate from from's values to to's (timing comes from to).

kill_all

pub fn kill_all()

Stop and forget every animation (e.g. between tests or page changes).

refresh_scroll

pub fn refresh_scroll()

Re-read scroll positions (after scrolling programmatically).

replay

pub fn replay(root: &Element)

Replay the declarative animations on root and inside it from the start (whatever their trigger).

replay_selector

pub fn replay_selector(selector: &str)

replay every element matching a CSS selector.

set

pub fn set(targets: impl Into<Targets>, vars: Vars) -> Animation

Set values immediately.

tick

pub fn tick(now_ms: f64)

Advance every animation to now_ms (a requestAnimationFrame time).

timeline

pub fn timeline() -> TimelineBuilder

Start building a timeline.

to

pub fn to(targets: impl Into<Targets>, vars: Vars) -> Animation

Animate from the current values to vars.

use_manual_clock

pub fn use_manual_clock(on: bool)

Use a manual clock (frames only via tick); for tests.

Re-exports