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
- sub태그
- sup태그
- 일반 형제 결합자
- i 태그
- RGB
- iframe
- not 의사클래스
- reveal in file explorer
- html tag i
- 아두이노
- focus 의사클래스
- html 태그
- iframe 태그
- Live Server
- height속성
- html
- br 태그
- background-color 속성
- css
- Checked 의사 클래스
- tag html
- 인접 형제 결합자
- id 선택자
- 전체 선택자
- RGBA
- width속성
- padding 속성
- 자식결합자
- go live
- 임베디드
Archives
- Today
- Total
so woon!
[FRAMER MOTION] Gestures 본문
학습일 : 2023. 05. 11
이번엔 이걸 만들어 보도록 하겠다.
hover시 z축을 기준으로 90도가 회전되고 크기가 조금 커지고
클릭 (tap) 했을 경우 크기가 원래대로 돌아오고 원이 된다.
<App.tsx>
import { styled } from "styled-components";
import { motion } from "framer-motion";
// style
const Wrapper = styled.div`
height: 100vh;
width: 100vw;
display: flex;
justify-content: center;
align-items: center;
`;
// 박스
const Box = styled(motion.div)`
width: 200px;
height: 200px;
background-color: rgba(255, 255, 255, 0.2);
border-radius: 40px;
box-shadow: 0 2px 3px rgba(0, 0, 0, 0.1), 0 10px 20px rgba(0, 0, 0, 0.06);
`;
// Variants
const boxVariants = {};
// whileHover, whileTap
function App() {
return (
<Wrapper>
<Box
whileHover={{ scale: 1.2, rotateZ: 90 }} // hover시 90도 z축 회전, 1.2배 커짐
whileTap={{ borderRadius: "1rem", scale: 1 }} // 클릭했을 경우 scale1로 돌리고 원이 됨
></Box>
</Wrapper>
);
}
export default App;
다 만들어 줬으니 variants를 사용하여 다시 해보도록 하자.
두개의 variants를 만들 것이다.
1. hover 할 경우
2. tap(클릭) 할 경우
// Variants 작성 - 이미 만들어 놓은걸 복붙해주면됨
const boxVariants = {
hover : { scale: 1.2, rotateZ: 90 },
tap : { borderRadius: "1rem", scale: 1 }
};
그리고 Box 컴포넌트에 variants={boxVariants} prop을 작성해줌
그리고 whileHover, whileTap을 각각 "hover", "tap" 이라고 변경해주면 된다.
전체 코드
<App.tsx>
import { styled } from "styled-components";
import { motion } from "framer-motion";
// style
const Wrapper = styled.div`
height: 100vh;
width: 100vw;
display: flex;
justify-content: center;
align-items: center;
`;
// 박스
const Box = styled(motion.div)`
width: 200px;
height: 200px;
background-color: rgba(255, 255, 255, 0.2);
border-radius: 40px;
box-shadow: 0 2px 3px rgba(0, 0, 0, 0.1), 0 10px 20px rgba(0, 0, 0, 0.06);
`;
// Variants
const boxVariants = {
hover : { scale: 1.2, rotateZ: 90 },
tap : { borderRadius: "1rem", scale: 1 }
};
// whileHover, whileTap
function App() {
return (
<Wrapper>
<Box
variants={boxVariants}
whileHover="hover" // hover시 90도 z축 회전, 1.2배 커짐
whileTap="tap" // 클릭했을 경우 scale1로 돌리고 원이 됨
></Box>
</Wrapper>
);
}
export default App;
실행결과
'Framer Motion > 개념정리' 카테고리의 다른 글
| [FRAMER MOTION] Drag Constraint (드래그 제약) (0) | 2023.05.12 |
|---|---|
| [FRAMER MOTION] Dragging (0) | 2023.05.11 |
| [FRAMER MOTION] Variants (1) | 2023.05.11 |
| [FRAMER MOTION] Animation (0) | 2023.05.11 |
| [FRAMER MOTION] Framer Motion 사용하기 (0) | 2023.05.10 |
Comments