Languages
[Edit]
EN

React - how to make animation with CSS transition property

3 points
Created by:
Zayaan-Rasmussen
543

Hi there! πŸ‘‹πŸ˜Š

In this article, I would like to show you how to make an animated rotating square in React using transition property. β­

Final effect:

transition property example (spinning square div)
transition property example (rotating square div)

In below example I've created three style objects: 

  • normalStyle which is the default style of our div element,
  • transformedStyle which is transformed style of our div element,
  • buttonStyle which is style of our button element.

The styles of our div have transition value set to '1s'. It means our component will change it's property values smoothly, over a given duration (over 1s). Additional transform parameter describes moving of an element. In our case transform rotates the element during 2s.

Runnable example:

πŸ“ Note:
If the duration is not specified, the transition will have no effect, because the default value is 0.

Related posts

Edit
1
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.

ReactJS - Blog posts

Native Advertising
πŸš€
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

β€οΈπŸ’» πŸ™‚

Join