leptos-use/examples/use_window_scroll/src/main.rs

35 lines
935 B
Rust
Raw Normal View History

2023-07-07 23:07:56 +01:00
use leptos::*;
use leptos_use::docs::{demo_or_body, Note};
use leptos_use::use_window_scroll;
#[component]
2023-07-27 18:06:36 +01:00
fn Demo() -> impl IntoView {
let (x, y) = use_window_scroll();
2023-07-07 23:07:56 +01:00
let div = document().create_element("div").unwrap();
div.set_attribute(
"style",
"position: absolute; top: 100%; left: 100%; width: 10000px; height: 10000px;",
)
.unwrap();
document().body().unwrap().append_child(&div).unwrap();
2023-07-27 19:48:21 +01:00
view! {
2023-10-23 20:15:05 -05:00
<div>See scroll values in the lower right corner of the screen.</div>
2023-07-07 23:07:56 +01:00
<div class="float m-5 area shadow-lg">
2023-10-23 20:15:05 -05:00
<Note class="mb-2">Scroll value</Note>
<div>x: {move || format!("{:.1}", x())} <br/> y: {move || format!("{:.1}", y())}</div>
2023-07-07 23:07:56 +01:00
</div>
}
}
fn main() {
_ = console_log::init_with_level(log::Level::Debug);
console_error_panic_hook::set_once();
2023-07-27 18:06:36 +01:00
mount_to(demo_or_body(), || {
2023-07-27 19:48:21 +01:00
view! { <Demo/> }
2023-07-07 23:07:56 +01:00
})
}