dioxus/examples/scroll_to_top.rs
2024-01-16 13:18:46 -06:00

31 lines
719 B
Rust

use dioxus::prelude::*;
fn main() {
launch_desktop(app);
}
fn app() -> Element {
let mut header_element = use_signal(|| None);
rsx! {
div {
h1 {
onmounted: move |cx| header_element.set(Some(cx.inner().clone())),
"Scroll to top example"
}
for i in 0..100 {
div { "Item {i}" }
}
button {
onclick: move |_| async move {
if let Some(header) = header_element.cloned() {
let _ = header.scroll_to(ScrollBehavior::Smooth).await;
}
},
"Scroll to top"
}
}
}
}