I want to incrementally rotate an image by 45 degrees one time, when the button was clicked, by using reactJs. But I have no clue how to do that. Can anyone give me some tips?
You can keep the current rotation in the state of your component. And add an onClick
handler which increments this by 45 at the time. Then use this variable in your render
. Here is a quick codepen of how it could be implemented: https://codepen.io/anon/pen/YZrrWM
Just use CSS animations with transform: rotate(45deg);
Add that rule to a new CSS class, then use an event listener in JavaScript on the button that adds the transform to the image.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With