How to get dimensions of the parent element for a mouseover / hover event? #1972
Replies: 1 comment 2 replies
-
Thank you for moving it over to the Discussions :) hopefully this can then help others new to I'll do a quick overview of some of the topics then as we run through the Rust code I'll hit on those topics again - so you can get the overview, then an example of how that works for this question :) A detour down
|
Beta Was this translation helpful? Give feedback.
-
Moving this question discussion from the discord to here per @mc1098 's suggestion.
What's the best way for for a mouse callback to get dimensions of the parent element the mouse is in?
For example, I need to calculate where the mouse is hovering horizontally proportional to the width of the component in a component to pass some values to an API. The values I get from offset_x() of the MouseEvent are in absolute pixels. I need to get the parent element's total width to calculate the proportion.
seems related to https://stackoverflow.com/questions/3234256/find-mouse-position-relative-to-element but with yew instead of jquery/js
I also see https://docs.rs/yew-component-size/0.1.0/yew_component_size/ but that dependency might be a little bit too bleeding edge (1 star on the repo currently).
Also some related discussion here #329 but this thread is 3 years old.
Beta Was this translation helpful? Give feedback.
All reactions