use leptos::html::Div; use leptos::*; use leptos_use::docs::{demo_or_body, BooleanDisplay}; use leptos_use::{use_scroll_with_options, ScrollBehavior, UseScrollOptions, UseScrollReturn}; #[component] fn Demo(cx: Scope) -> impl IntoView { let el = create_node_ref::
(cx); let (smooth, set_smooth) = create_signal(cx, false); let behavior = Signal::derive(cx, move || { if smooth.get() { ScrollBehavior::Smooth } else { ScrollBehavior::Auto } }); let UseScrollReturn { x, y, set_x, set_y, is_scrolling, arrived_state, directions, .. } = use_scroll_with_options(cx, el, UseScrollOptions::default().behavior(behavior)); view! { cx,
"top_left"
"bottom_left"
"top_right"
"bottom_right"
"Scroll Me"
"X Position"
() { set_x(num); } } type="number" min="0" max="200" step="10" />
"Y Position"
() { set_y(num); } } type="number" min="0" max="200" step="10" />
"Is Scrolling"
"Top Arrived"
"Right Arrived"
"Bottom Arrived"
"Left Arrived"
"Scrolling Up"
"Scrolling Right"
"Scrolling Down"
"Scrolling Left"
} } fn main() { _ = console_log::init_with_level(log::Level::Debug); console_error_panic_hook::set_once(); mount_to(demo_or_body(), |cx| { view! { cx, } }) }