Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

use_scroll

We have to check if the scroll amount is close enough to some threshold in order to more accurately calculate arrivedState. This is because scrollTop/scrollLeft are non-rounded numbers, while scrollHeight/scrollWidth and clientHeight/clientWidth are rounded. https://developer.mozilla.org/en-US/docs/Web/API/Element/scrollHeight#determine_if_an_element_has_been_totally_scrolled

Installation

cargo add leptos-use-scroll

Options

UseScrollOptions

Options for use_scroll. Options for use_scroll_with_options.

Every option is set with a builder method of the same name, e.g. UseScrollOptions::default().throttle(...). See also the API docs.

throttle

Type: f64

Throttle time in milliseconds for the scroll events. Defaults to 0 (disabled).

idle

Type: f64

After scrolling ends we wait idle + throttle milliseconds before we consider scrolling to have stopped. Defaults to 200.

offset

Type: ScrollOffset

Threshold in pixels when we consider a side to have arrived (UseScrollReturn::arrived_state).

on_scroll

Type: Rc<dyn Fn(web_sys::Event)>

Callback when scrolling is happening.

on_stop

Type: Rc<dyn Fn(web_sys::Event)>

Callback when scrolling stops (after idle + throttle milliseconds have passed).

event_listener_options

Type: UseEventListenerOptions

Options passed to the addEventListener("scroll", ...) call

behavior

Type: Signal<ScrollBehavior>

When changing the x or y signals this specifies the scroll behaviour. Can be Auto (= not smooth) or Smooth. Defaults to Auto.

Source

Source • Demo • Docs