Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 |
Tags
- width속성
- br 태그
- height속성
- go live
- Checked 의사 클래스
- reveal in file explorer
- html 태그
- id 선택자
- sup태그
- html
- RGBA
- 전체 선택자
- 일반 형제 결합자
- 아두이노
- focus 의사클래스
- css
- Live Server
- not 의사클래스
- RGB
- padding 속성
- background-color 속성
- i 태그
- iframe 태그
- 임베디드
- sub태그
- 자식결합자
- tag html
- 인접 형제 결합자
- html tag i
- iframe
Archives
- Today
- Total
so woon!
[STYLED COMPONENTS] animation 본문
학습일 : 2023. 03. 28
styled-component 안에서 animation을 주기 위해서는
helper function을 import 해주어야 한다
import styled, {keyframes} from "styled-components";
이렇게 import를 해주고
회전하는 animation을 만들어 보고자 한다.
이렇게 먼저 animation을 keyframes를 사용하여 정의해주고
(rotationAnimation 이 이름은 바꿔줘도 상관없다.)
// animation
const rotationAnimation = keyframes`
from {
transform: rotate(0deg);
}
to {
transform: rotate(360deg);
}
`;
사용은 이런식으로 하면 된다.
// Box
const Box = styled.div`
background-color: salmon;
height: 200px;
width: 200px;
animation: ${rotationAnimation} 1s linear infinite;
`;
전체 코드
import styled, { keyframes } from "styled-components";
const Wrapper = styled.div`
display: flex;
`;
// animation
const rotationAnimation = keyframes`
from {
transform: rotate(0deg);
}
to {
transform: rotate(360deg);
}
`;
// Box
const Box = styled.div`
background-color: salmon;
height: 200px;
width: 200px;
animation: ${rotationAnimation} 1s linear infinite;
`;
function App() {
return (
<Wrapper>
<Box />
</Wrapper>
);
}
export default App;
실행결과
0%, 50%, 100% 방식으로 지정해주면
import styled, { keyframes } from "styled-components";
const Wrapper = styled.div`
display: flex;
`;
// animation
const rotationAnimation = keyframes`
0% {
transform:rotate(0deg);
border-radius: 0px;
background-color: red;
}
50% {
transform:rotate(360deg);
border-radius: 100px;
background-color: yellow;
}
100%{
transform:rotate(0deg);
border-radius: 0px;
background-color: blueviolet;
}
`;
// Box
const Box = styled.div`
background-color: salmon;
height: 200px;
width: 200px;
animation: ${rotationAnimation} 10s linear infinite;
`;
function App() {
return (
<Wrapper>
<Box />
</Wrapper>
);
}
export default App;
애니메이션 너무 귀엽고 재밌다
'Styled Components > 개념정리' 카테고리의 다른 글
[STYLED COMPONENTS] 컴포넌트 안에서 컴포넌트 타겟팅 하기 (0) | 2023.03.29 |
---|---|
[STYLED COMPONENTS] styled 안 target 처리하기 (0) | 2023.03.28 |
[STYLED COMPONENTS] as 를 사용하여 element 교체하기 (0) | 2023.03.28 |
[STYLED COMPONENTS] 컴포넌트 확장하기 (0) | 2023.03.27 |
[STYLED COMPONENTS] styled-components 사용하기 (0) | 2023.03.27 |
Comments