#7 ANIMATIONS
Last updated
Was this helpful?
Last updated
Was this helpful?
Examples | Framer for Developers
Framer Motion
Reactμ© production-ready λͺ¨μ λΌμ΄λΈλ¬λ¦¬ (μ€ν μμ€)
https://github.com/framer/motion
npm i framer-motion
import { motion } from "framer-motionβ
motion μ¬μ©μ κΈ°μ‘΄μ <div> μ μ¬μ©ν μ μμ
<motion.div> λ‘ μ¬μ©ν΄μΌν¨
CRACO
CRACO(Create React App Configuration Override)λ create-react-appμ μν μ½κ³ μ΄ν΄νκΈ° μ¬μ΄ configuration λ μ΄μ΄μ λλ€. μ ν리μΌμ΄μ rootμ λ¨μΌ configuration(μ: craco.config.js) νμΌμ μΆκ°νκ³ eslint, babel, postcss configuration λ±μ μ¬μ©μ μ§μ νμ¬ 'eject'λ₯Ό μ¬μ©νμ§ μκ³ create-react-app λ° μ¬μ©μ μ§μ μ λͺ¨λ μ΄μ μ μ»μΌμμμ€.
https://github.com/gsoft-inc/craco
https://github.com/gsoft-inc/craco/blob/master/packages/craco/README.md#installation
craco.config.js
Framer Motionμ μ λλ©μ΄μ μ λͺ¨μ μ»΄ν¬λνΈμ μ μ°ν animate μμ±μ ν΅ν΄ μ μ΄λλ€.
κ°λ¨ν μ λλ©μ΄μ μ animate propsμμ μ§μ κ°μ μ€μ ν μ μλ€.
initial - μμ / transition - λ³ν λ°©λ² / animate - μ’ λ£
Variants μ¬λ¬ μ λλ©μ΄μ μ ν©μΉ μ μμ & κΉλν μ½λ
λΆλͺ¨ μμμ μ λλ©μ΄μ κ³Ό propsλ₯Ό μμ μμμλ μ λ¬νλ€.
& κ° μμ μμμ κ°κ° λλ μ΄ μ£Όλ λ±μ λ―ΈμΉ κΈ°λ₯λ κ°λ₯νλ€.
delayChildren: λλ μ΄ μκ°(μ΄) ν νμ μ λλ©μ΄μ μμ
staggerChildren: νμ μ»΄ν¬λνΈμ μ λλ©μ΄μ μ μ§μ μκ°(μ΄)λ§νΌ μμ°¨ μλ₯Ό λ€μ΄, staggerChildrenμ΄ 0.01μ΄λ©΄ 첫 λ²μ§Έ μμμ 0μ΄, λ λ²μ§Έ μμμ 0.01μ΄, μΈ λ²μ§Έ μμμ 0.02μ΄ μ§μ°. κ³μ°λ stagger λλ μ΄κ° delayChildrenμ μΆκ°λλ€.
inherit: boolean
λΆλͺ¨λ‘λΆν° variant λ³κ²½ μ¬νμ μμνμ§ μλλ‘ νλ €λ©΄ falseλ‘ μ€μ .
whileHover - νΈλ² μ€μΌλ μλν μ λλ©μ΄μ
whileTap - ν΄λ¦ μ€μΌλ μλν μ λλ©μ΄μ
Drag
drag: boolean | βxβ | βyβ
λκΈ° νμ±ν- κΈ°λ³Έ false μλ°©ν₯ λλκ·Έλ₯Ό μνλ©΄ true, νΉμ λ°©ν₯μΌλ‘ νλ €λ©΄ x or y μ€μ
whileDrag - λλκ·Έ μ€μΌλ μλν μ λλ©μ΄μ
dragConstraints - λλκ·Έκ° νμ©λλ λ²μ (1. ν½μ ν¬κΈ° μ΄μ© 2. ref μ΄μ©)
dragSnapToOrigin - μλ μλ¦¬λ‘ λμκ°
dragElastic - μΈλΆ μ μ½ μ‘°κ±΄μμ νμ©λλ μ΄λ μ λ 0=μμ§μ μμ 1=μ 체 μμ§μ κΈ°λ³Έ 0.5 falseκ°λ₯
νΉμ κ°μ μΆμ νμ§λ§ stateκ° μλλ€?!
.set() .get() λ©μλλ‘ κ°μ μ λ°μ΄νΈνκ±°λ μ§μ ν μ μλ€.
νΉμ κ°μ λ€λ₯Έ κ°μΌλ‘ λ³νν΄μ€λ€.
useTransform(x, input, output) β xμ κ°μ input λ²μμμ output λ²μλ‘ λ³ννλ€.
λ·°ν¬νΈκ° μ€ν¬λ‘€ λ λ μ λ°μ΄νΈλλ MotionValues κ°μ 리ν΄νλ€.
scrollX - μ€μ μν μ€ν¬λ‘€ ν½μ
scrollY - μ€μ μμ§ μ€ν¬λ‘€ ν½μ
scrollXProgress - 0~1 μ¬μ΄μ μν μ€ν¬λ‘€
scrollYProgress - 0~1 μ¬μ΄μ μμ§ μ€ν¬λ‘€
μ΄ κ°μ μ΄μ©ν΄ μ€ν¬λ‘€ μμΉμ λ°λΌ μ λλ©μ΄μ μ μΆκ°ν μ μμ !!
npm-check-updates μ¬μ©
npm install -g npm-check-updates // ν¨ν€μ§ μ€μΉ
ncu -u // μ λ°μ΄νΈ κ°λ₯ν νλͺ© νμΈ
npm install // μ λ°μ΄νΈ
fontAwsome μμ svg νμΌ κ°μ Έμ€κΈ°
path(SVG) β λͺ¨μμ μ μνλ μ리먼νΈ
transition κ°κ° μ€ μ μμ γ γ γ· !
Line drawing
svg μ리먼νΈμ 'pathLength', 'pathSpacing', 'pathOffset' μμ±μ μ¬μ©νμ¬ Line drawing μ λλ©μ΄μ μ λ§λ€ μ μμ΅λλ€.
https://www.framer.com/docs/examples/#line-drawing
path (SVG)
path SVG μ리먼νΈλ λͺ¨μμ μ μνλ μΌλ° μ리먼νΈμ λλ€.λͺ¨λ κΈ°λ³Έ λͺ¨μμ path μ리먼νΈλ‘ λ§λ€ μ μμ΅λλ€.
pathμ μμ± dλ κ²½λ‘μ λͺ¨μμ μ μν©λλ€.
https://developer.mozilla.org/en-US/docs/Web/SVG/Element/path
Path
motion.path μ»΄ν¬λνΈλ μΈ κ°μ§ κ°λ ₯ν SVG path μμ±μΈ pathLength, pathSpacing λ° pathOffsetμ κ°μ§κ³ μμ΅λλ€. μλ κ²½λ‘ μΈ‘μ μ΄ νμ μμ΄ λͺ¨λ 0κ³Ό 1 μ¬μ΄μ κ°μΌλ‘ μ€μ λ©λλ€.
Line drawing
μ 그리기 μ λλ©μ΄μ μ pathLength, pathSpacing λ° pathOffsetμ μΈ κ°μ§ νΉμ μμ±μ μ¬μ©νμ¬ λ§μ SVG μμλ‘ λ§λ€ μ μμ΅λλ€.
ex) motion.circle initial={{ pathLength: 0 }} animate={{ pathLength: 1 }}
https://www.framer.com/docs/examples/#line-drawing
μ½λ
μ‘°κ±΄λΆ showing
<AnimatePresence></AnimatePresence> μ¬μ΄μ μ‘°κ±΄λΆ λ±μ₯&μμ κΈ°λ₯μ΄ μμΌλ©΄ animate κΈ°λ₯
initial=ββ, animate=ββ, exit=ββ
exit - μ¬λΌμ§λ λ°μν μ λλ©μ΄μ
μ½λ
next
prev
custom
κ° μ λλ©μ΄μ μ»΄ν¬λνΈμ λν΄ λμ variants λ₯Ό λ€λ₯΄κ² μ μ©ν λ μ¬μ©νλ μ¬μ©μ μ§μ λ°μ΄ν°
μ½λ
μ λλ©μ΄μ μ μ μ©νμ§ μμλ μμμ μ μ©ν¨
layout
λ³ν λ°μνλ©΄ μλ animation μ μ©
Animate between components
λμΌν layoutId propμ κ°μ§ λͺ¨μ μ»΄ν¬λνΈ κ° μ λλ©μ΄μ μ μ μ©νλ€.
μ½λ