-
I have SSR web application. I would like to add an animation when the page is loaded. So, my plan is to tap into However, I'm struggling to get access to window object. Following will panic at the server start. I assume because I'm trying to access a window in server component. let window = window(); Window doesn't seem to be a I think what I'm trying to do is something like below but I want it to run only on client. In NextJS I would have checked whether #[component]
fn Header() -> impl IntoView {
let window = leptos::window();
let (animate, set_animate) = create_signal(false);
let a = Closure::<dyn Fn()>::new(move || set_animate(true));
window.add_event_listener_with_callback("load", a.as_ref().unchecked_ref());
view! {
<div>
<h1
class="
transition-transform
duration-1000
ease-in-out
translate-x-32
opacity-0
"
class:translate-x-0=move|| {animate()}
class:opacity-1=move|| {animate()}
>
"Hi!"
</h1>
</div>
}
} |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
You can use |
Beta Was this translation helpful? Give feedback.
You can use
window_event_listener
, which will only run on the browser. In general,create_effect
only runs on the client.