
正文
[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`
% { border-radius: 5px; }
% { border-radius: %; }
% { border-radius: 5px; }
`; const spin = keyframes`
from { transform: rotate(0deg); }
to { transform: rotate(360deg); }
`; const Ball = styled.div`
width: 64px;
height: 64px;
border-radius: %;
margin: auto;
background-color: #08aeea;
background-image: linear-gradient(0deg, #08aeea %, #2af598 %);
animation: ${morph} 1s linear infinite, ${spin} 1s ease-in-out infinite;
`; const App = () => <Ball />; export default App;






