mirror of
https://github.com/adoyle0/leptos-use.git
synced 2025-02-02 10:54:15 -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::docs::{demo_or_body, BooleanDisplay};
|
||||||
use leptos_use::{use_scroll_with_options, ScrollBehavior, UseScrollOptions, UseScrollReturn};
|
use leptos_use::{use_scroll_with_options, ScrollBehavior, UseScrollOptions, UseScrollReturn};
|
||||||
|
|
||||||
|
use web_sys::Event;
|
||||||
|
|
||||||
#[component]
|
#[component]
|
||||||
fn Demo(cx: Scope) -> impl IntoView {
|
fn Demo(cx: Scope) -> impl IntoView {
|
||||||
let el = create_node_ref::<Div>(cx);
|
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 {
|
let UseScrollReturn {
|
||||||
x,
|
x,
|
||||||
y,
|
y,
|
||||||
|
@ -24,7 +34,14 @@ fn Demo(cx: Scope) -> impl IntoView {
|
||||||
arrived_state,
|
arrived_state,
|
||||||
directions,
|
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,
|
view! { cx,
|
||||||
<div class="flex">
|
<div class="flex">
|
||||||
|
|
Loading…
Add table
Reference in a new issue