⚠️ This lesson is retired and might contain outdated information.

Animate your user interface in React with styled-components and "keyframes"

Share this video with your friends

Social Share Links

Send Tweet
Published 7 years ago
Updated 2 years ago

In this lesson, we learn how to handle CSS keyframe animations in styled-components, via the 'keyframes' helper.

[00:00] Here is a react app that is a simple bowl component, which is just a DIV with some styles applied to it. Here are some CSS keyframes animations that animate the rotate and border-radius properties. To use keyframe animations in style components, we'll import the keyframes named exports. I'll create the const moff and right keyframes followed by bactics.

[00:23] In here, I'll paste the declaration of the moff animation. Let's do the same one more time, const spin equals keyframes, and we'll paste the CSS in there, too. In the bowl component here, which is a style component, I can now access these keyframes.

[00:40] Animation, dollar sign curly braces, moff -- which is the name of the constant here -- and we give it a duration of one second, a linear easing, and make it loop for ever. Let's save and check it out.

[00:54] Here we go. The bowl now looks like its breathing in and out. Let's take it for spin by chaining the other keyframes animation. Spin, one second as well. This time ease in, out, and infinite again. That's how you handle keyframe animation in style components.

egghead
egghead
~ 4 minutes ago

Member comments are a way for members to communicate, interact, and ask questions about a lesson.

The instructor or someone from the community might respond to your question Here are a few basic guidelines to commenting on egghead.io

Be on-Topic

Comments are for discussing a lesson. If you're having a general issue with the website functionality, please contact us at support@egghead.io.

Avoid meta-discussion

  • This was great!
  • This was horrible!
  • I didn't like this because it didn't match my skill level.
  • +1 It will likely be deleted as spam.

Code Problems?

Should be accompanied by code! Codesandbox or Stackblitz provide a way to share code and discuss it in context

Details and Context

Vague question? Vague answer. Any details and context you can provide will lure more interesting answers!

Markdown supported.
Become a member to join the discussionEnroll Today