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.1.0"
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 are triggered by calling 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,
βΈ»
π§ 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)
βΈ»
π License
MIT or Apache-2.0, at your option.
βΈ»