Post

styled-components에서 keyframes 작성하기

styled.div 대신에 keyframes을 사용한다.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
import styled, { keyframes } from 'styled-components'

const fadeIn = keyframes`
  0% {
    opacity: 0;
  }
  100% {
    opacity: 1;
  }
`

const FadeInButton = styled.button`
  animation: 1s ${fadeIn} ease-out;
`


스타일 규칙을 부분적으로 작성하는 경우 css를 붙여 사용해야 한다.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
import styled, { css, keyframes } from 'styled-components'

const pulse = keyframes`
  0% {
    opacity: 0;
  }
  100% {
    opacity: 1;
  }
`

const animation = (props) =>
  css`
    ${pulse} ${props.animationLength} infinite alternate;
  `

const PulseButton = styled.button`
  animation: ${animation};
`


keyframes

This post is licensed under CC BY 4.0 by the author.