mirror of
https://github.com/adoyle0/leptos-use.git
synced 2025-01-23 00:59:22 -05:00
Merge pull request #10 from sectore/fix/use_scroll
Add callback example for `use_scroll`
This commit is contained in:
commit
f7040bff92
1 changed files with 18 additions and 1 deletions
|
@ -3,6 +3,8 @@ use leptos::*;
|
|||
use leptos_use::docs::{demo_or_body, BooleanDisplay};
|
||||
use leptos_use::{use_scroll_with_options, ScrollBehavior, UseScrollOptions, UseScrollReturn};
|
||||
|
||||
use web_sys::Event;
|
||||
|
||||
#[component]
|
||||
fn Demo(cx: Scope) -> impl IntoView {
|
||||
let el = create_node_ref::<Div>(cx);
|
||||
|
@ -15,6 +17,14 @@ fn Demo(cx: Scope) -> impl IntoView {
|
|||
}
|
||||
});
|
||||
|
||||
let on_stop = |_: Event| {
|
||||
log!("scrolling stopped");
|
||||
};
|
||||
|
||||
let on_scroll = |_: Event| {
|
||||
log!("scrolling");
|
||||
};
|
||||
|
||||
let UseScrollReturn {
|
||||
x,
|
||||
y,
|
||||
|
@ -24,7 +34,14 @@ fn Demo(cx: Scope) -> impl IntoView {
|
|||
arrived_state,
|
||||
directions,
|
||||
..
|
||||
} = use_scroll_with_options(cx, el, UseScrollOptions::default().behavior(behavior));
|
||||
} = use_scroll_with_options(
|
||||
cx,
|
||||
el,
|
||||
UseScrollOptions::default()
|
||||
.behavior(behavior)
|
||||
.on_stop(on_stop.clone())
|
||||
.on_scroll(on_scroll.clone()),
|
||||
);
|
||||
|
||||
view! { cx,
|
||||
<div class="flex">
|
||||
|
|
Loading…
Add table
Reference in a new issue