Skip to content

struct

ScrollTrigger

pub struct ScrollTrigger {
    pub start: Edge,
    pub end: Edge,
    pub scrub: Option<f64>,
    pub actions: [Action; 4],
    pub once: bool,
}

When a scroll-triggered animation plays: where it starts and ends in the viewport, whether it's scrubbed, and what each crossing does.

Fields

start

pub start: Edge

When it starts.

end

pub end: Edge

When it ends.

scrub

pub scrub: Option<f64>

Some(0) ties progress to the scroll directly; Some(s) smooths it over s seconds; None plays on enter instead.

actions

pub actions: [Action; 4]

onEnter, onLeave, onEnterBack, onLeaveBack.

once

pub once: bool

Stop watching after the first enter.

Methods

toggle_actions

pub fn toggle_actions(self, s: &str) -> Option<ScrollTrigger>

The trigger with its four crossing actions set from s ("play none none reverse": enter, leave, enter back, leave back), if each is an action.

progress

pub fn progress(&self, top: f64, height: f64, viewport: f64) -> f64

Progress through the start→end range (unclamped), from the trigger's viewport-relative top and height and the viewport height.

crossing

pub fn crossing(previous: f64, now: f64) -> Option<Crossing>

The crossing between two progress readings, if any.

action

pub fn action(&self, c: Crossing) -> Action

What crossing c does.

Trait implementations