-
this is the general idea of how you do it in solidjs, const [ref, setRef] = createSignal()
return <div ref={setRef} style={ref() && { left: `${position() * ref().offsetWidth - adjustment}px` }} /> but it doesn't seem to work w/ leptos (the log returns let elem_ref = NodeRef::new(cx);
let vw = view! {cx,
<div _ref=elem_ref>
<div style="height: 10px" />
</div>
};
create_effect(cx, move |_| {
console_log(&format!("{:?}", elem_ref.get().unwrap().get_bounding_client_rect().height()));
});
vw i also tried wrapping NodeRef with a signal, but then i can't use it in is there some way to delay execution of the |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Yeah the It might be a little hacky but how about something like this, using let elem_ref = NodeRef::new(cx);
create_effect(cx, move |_| {
if let Some(elem) = elem_ref.get() {
request_animation_frame(move || {
console_log(&format!("{:?}", elem.get_bounding_client_rect().height()));
});
}
});
view! {cx,
<div _ref=elem_ref>
<div height=10 width=3 />
</div>
} |
Beta Was this translation helpful? Give feedback.
Yeah the
NodeRef
is filled on element creation, not on mounting to the DOM.It might be a little hacky but how about something like this, using
request_animation_frame
to delay until it's mounted. (I haven't tried this to see if it actually works.)