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

Posted Answer1215

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了[React] Animate your user interface in React with styled-components and "keyframes"相关的知识,希望对你有一定的参考价值。

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

 

import React from "react";
import styled, { keyframes } from "styled-components";

const morph = keyframes`
  0% { border-radius: 5px; }
  50% { border-radius: 50%; }
  100% { border-radius: 5px; }
`;

const spin = keyframes`
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
`;

const Ball = styled.div`
  width: 64px;
  height: 64px;
  border-radius: 50%;
  margin: 0 auto;
  background-color: #08aeea;
  background-image: linear-gradient(0deg, #08aeea 0%, #2af598 100%);
  animation: ${morph} 1s linear infinite, ${spin} 1s ease-in-out infinite;
`;

const App = () => <Ball />;

export default App;

 

以上是关于[React] Animate your user interface in React with styled-components and "keyframes"的主要内容,如果未能解决你的问题,请参考以下文章

[React Native] Animate Styles of a React Native View with Animated.timing

React:使用 Animate on Scroll 库条件渲染 CSS 类

react-hook的简单的动画插件react-simple-animate(其实是react插件,但是这里只介绍react-hook的简单用法)

[React] Use React Fragments to make your DOM tree cleaner

Build your own React_4 理解React纤维

Build your own React_4 理解React纤维