Autoplay

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

    Simon VrachliotisSimon Vrachliotis

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

    reactReact
    Code

    Code

    Become a Member to view code

    You must be a Member to view code

    Access all courses and lessons, track your progress, gain confidence and expertise.

    Become a Member
    and unlock code for this lesson
    Transcript

    Transcript

    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.

    Discuss

    Discuss