Files
dioxus/packages/router/src/history/web_scroll.rs
T
Evan Almloff a09548d80e Remove implicit optional dependency features (#2512)
* remove implicit optional dependency features

* switch to new features in desktop, router and signals crates
2024-06-18 18:39:15 -05:00

23 lines
601 B
Rust

use gloo::render::{request_animation_frame, AnimationFrame};
use web_sys::Window;
#[derive(Clone, Copy, Debug, Default)]
pub(crate) struct ScrollPosition {
pub x: f64,
pub y: f64,
}
impl ScrollPosition {
pub(crate) fn of_window(window: &Window) -> Self {
Self {
x: window.scroll_x().unwrap_or_default(),
y: window.scroll_y().unwrap_or_default(),
}
}
pub(crate) fn scroll_to(&self, window: Window) -> AnimationFrame {
let Self { x, y } = *self;
request_animation_frame(move |_| window.scroll_to_with_x_and_y(x, y))
}
}