We're dsplce.co, check out our work on github.com/dsplce-co ๐ค
dioxus-animate
โจ CSS Class Animations for Dioxus โ Time-based CSS class manipulation for smooth animations in Dioxus apps. This crate provides ergonomic macros to sequence CSS class additions and removals with precise timing control.
๐ค Features
โ Time-based CSS class manipulation โ Ergonomic macro-based API โ Group multiple operations together โ Async-powered with no blocking โ Type-safe animation sequences
๐ฆ Installation
Add to your Cargo.toml:
[]
= "0.2"
This crate requires Rust 2024 edition.
๐งช Usage
1. Basic Animation Sequence
Use the use_animate! macro to create timed CSS class operations:
use *;
use *;
2. Grouped Operations
Execute multiple class operations simultaneously using parentheses:
let animation = use_animate!;
3. Complex Animation Sequences
Chain multiple operations with precise timing:
let animation = use_animate!;
4. Triggering Animations
Animations can be triggered in two ways:
Method 1: Using Element References
Call start() with a reference to the mounted element:
// In your event handler
animation.start;
The element reference is obtained through the onmounted event:
onmounted: move |event| element_ref.set,
Method 2: Using Element ID
Call start_for_id() with the element's ID string:
let animation = use_animate!;
let trigger_animation = move |_| ;
rsx!
This method is useful when you don't need to store element references or when targeting elements by ID is more convenient.
๐ง How It Works
- Define: Use
use_animate!to define your animation sequence with timestamps and operations - Mount: Capture element reference with
onmounted - Trigger: Call
animation.start(element_ref.into())to begin the sequence - Execute: Operations run asynchronously at their specified times
Time values are in milliseconds and represent cumulative time from animation start.
๐ API Reference
use_animate!
Creates an animation sequence with the following syntax:
use_animate!;
Operations:
add("class-names")- Adds CSS classes to the elementremove("class-names")- Removes CSS classes from the element(op1; op2; ...)- Groups multiple operations to execute simultaneously
Time values:
- Expressed in milliseconds
- Cumulative from animation start
- Must be in ascending order (think CSS keyframes)
Animation Methods
start(element_ref)
Starts the animation sequence on the provided element reference:
animation.start;
start_for_id(id)
Starts the animation sequence on an element with the specified ID:
animation.start_for_id;
This method is convenient when you prefer to target elements by ID rather than maintaining element references.
๐ Repo & Contributions
๐ฆ Crate: crates.io/crates/dioxus-animate ๐ ๏ธ Repo: github.com/dsplce-co/dioxus-animate
Contributions, issues, ideas? Hit us up ๐ค
๐ License
MIT or Apache-2.0, at your option.