I think this should achieve your goal
let some_on_click_handler = Callback::new(move |evt: FretClickEvent| {
if let Some(node) = error_text_node_ref.get() {
// access the current style
let style = window().get_computed_style(&node).unwrap().unwrap();
let animation_name: String = style.get_property_value("animation-name").unwrap();
// [...] do something with this information
// change the style
node.style("animation-name: shake");
}
// some other logic for setting error_text..
});
First, you get all the current styling of an element using Window
's get_computed_style()
(Rust binding by web_sys of the JS function) and then use get_property_value()
to access a specific CSS style value.
Then, to set the style you use the style()
which you found yourself. You can e.g. pass it a dynamically created String
.
instead I want to access the style and change one property on it
What you're asking for here is mutable reference to a specific style, and this is impossible as far as I know.