본문으둜 κ±΄λ„ˆλ›°κΈ°

CSS 속성 14. animation

❗️ ν•΄λ‹Ή 글은 패슀트캠퍼슀 - ν”„λ‘ νŠΈμ—”λ“œ 개발 κ°•μ˜μ—μ„œ HTML & CSS, SASS(SCSS) Part의 λ°•μ˜μ›… κ°•μ‚¬λ‹˜μ˜ κ°•μ˜μžλ£Œλ₯Ό μ •λ¦¬ν•œ κ²ƒμž…λ‹ˆλ‹€.

animation#

μš”μ†Œμ— μ• λ‹ˆλ©”μ΄μ…˜μ„ μ„€μ •/μ œμ–΄ - 단좕 속성


속성 κ°’#

κ°’μ˜λ―ΈκΈ°λ³Έκ°’
animation-name@keyframes κ·œμΉ™μ˜ 이름을 지정none
animation-durationμ• λ‹ˆλ©”μ΄μ…˜μ˜ 지속 μ‹œκ°„ μ„€μ •0s
animation-timing-function타이밍 ν•¨μˆ˜ 지정ease
animation-delayμ• λ‹ˆλ©”μ΄μ…˜μ˜ λŒ€κΈ° μ‹œκ°„ μ„€μ •0s
animation-iteration-countμ• λ‹ˆλ©”μ΄μ…˜μ˜ 반볡 횟수 μ„€μ •1
animation-directionμ• λ‹ˆλ©”μ΄μ…˜μ˜ 반볡 λ°©ν–₯ μ„€μ •normal
animation-fill-modeμ• λ‹ˆλ©”μ΄μ…˜μ˜ μ „ν›„ μƒνƒœ(μœ„μΉ˜) μ„€μ •none
animation-play-stateμ• λ‹ˆλ©”μ΄μ…˜μ˜ μž¬μƒκ³Ό 정지 μ„€μ •running

☝️ animation 속성 μžμ²΄κ°€ μ• λ‹ˆλ©”μ΄μ…˜μ„ λ§Œλ“€μ–΄μ£ΌλŠ” 것은 μ•„λ‹ˆκ³  @keyframes 에 μ„€μ •λœ μ• λ‹ˆλ©”μ΄μ…˜μ„ μ œμ–΄ν•˜λŠ” κ°œλ…μ΄λ‹€.


μ‚¬μš©λ²•#

animation: μ• λ‹ˆλ©”μ΄μ…˜μ΄λ¦„ μ§€μ†μ‹œκ°„ [νƒ€μ΄λ°ν•¨μˆ˜ λŒ€κΈ°μ‹œκ°„ 반볡횟수 반볡방ν–₯ μ „ν›„μƒνƒœ μž¬μƒ/정지];
.box {width: 100px;height: 100px;background: tomato;animation: hello 2s linear infinite both;}@keyframes hello {0% { width: 200px; }100% { width: 50px; }}

@keyframes#

2개 μ΄μƒμ˜ μ• λ‹ˆλ©”μ΄μ…˜ 쀑간 μƒνƒœ(ν”„λ ˆμž„)을 지정


μ‚¬μš©λ²•#

@keyframes μ• λ‹ˆλ©”μ΄μ…˜μ΄λ¦„ {0% { 속성: κ°’; }50% { 속성: κ°’; }100% { 속성: κ°’; }}

예제#

<div class="box"></div>
.box {width: 100px;height: 100px;background: tomato;border-radius: 10px;}.box:hover {animation: my-animation 3s infinite alternate;}@keyframes my-animation {0% {width: 100px;background: tomato;}75% {width: 500px;background: dodgerblue;}100% {width: 300px;background: yellowgreen;}}

☝️ transition 에 λΉ„ν•΄ @keyframes λ₯Ό μ΄μš©ν•˜λ©΄ μ• λ‹ˆλ©”μ΄μ…˜μ„ 더 μ„ΈλΆ€μ μœΌλ‘œ μ„€μ •ν• μˆ˜ μžˆλ‹€.


animation-name#

@keyframes κ·œμΉ™(μ• λ‹ˆλ©”μ΄μ…˜ ν”„λ ˆμž„)의 이름을 지정 - κ°œλ³„ 속성


속성 κ°’#

κ°’μ˜λ―ΈκΈ°λ³Έκ°’
noneμ• λ‹ˆλ©”μ΄μ…˜μ„ μ§€μ •ν•˜μ§€ μ•ŠμŒnone
@keyframes 이름이름이 μΌμΉ˜ν•˜λŠ” @keyframes κ·œμΉ™μ˜ μ• λ‹ˆλ©”μ΄μ…˜μ„ 적용

animation-duration#

μ• λ‹ˆλ©”μ΄μ…˜μ˜ 지속 μ‹œκ°„ μ„€μ • - κ°œλ³„ 속성


속성 κ°’#

κ°’μ˜λ―ΈκΈ°λ³Έκ°’
μ‹œκ°„μ§€μ† μ‹œκ°„μ„ μ„€μ •0s

animation-timing-function#

타이밍 ν•¨μˆ˜(μ• λ‹ˆλ©”μ΄μ…˜ 효과λ₯Ό κ³„μ‚°ν•˜λŠ” 방법) 지정 - κ°œλ³„ 속성


속성 κ°’#

κ°’μ˜λ―ΈκΈ°λ³Έκ°’Cubic Bezier κ°’
easeλΉ λ₯΄κ²Œ - 느리게easecubic-bezier(.25, .1, .25, 1)
linearμΌμ •ν•˜κ²Œcubic-bezier(0, 0, 1, 1)
ease-in느리게 - λΉ λ₯΄κ²Œcubic-bezier(.42, 0, 1, 1)
ease-outλΉ λ₯΄κ²Œ - 느리게cubic-bezier(0, 0, .58, 1)
ease-in-out느리게 - λΉ λ₯΄κ²Œ - 느리게cubic-bezier(.42, 0, .58, 1)
cubic-bezier(n, n, n, n)μžμ‹ λ§Œμ˜ 값을 μ •μ˜ ( 0 ~ 1 )
steps(n)n 번 λΆ„ν• λœ μ• λ‹ˆλ©”μ΄μ…˜

animation-delay#

μ• λ‹ˆλ©”μ΄μ…˜μ˜ λŒ€κΈ° μ‹œκ°„ μ„€μ • - κ°œλ³„ 속성


속성 κ°’#

κ°’μ˜λ―ΈκΈ°λ³Έκ°’
μ‹œκ°„λŒ€κΈ° μ‹œκ°„μ„ μ„€μ •0s

☝️ μŒμˆ˜κ°€ ν—ˆμš©λœλ‹€. μŒμˆ˜κ°€ μžˆμ„ 경우 μ• λ‹ˆλ©”μ΄μ…˜μ€ λ°”λ‘œ μ‹œμž‘λ˜μ§€λ§Œ, κ·Έ κ°’λ§ŒνΌμ• λ‹ˆλ©”μ΄μ…˜μ΄ μ•žμ„œ μ‹œμž‘ν•œλ‹€. (μ• λ‹ˆλ©”μ΄μ…˜ μ£ΌκΈ° 도쀑에 μ‹œμž‘)ex) -1s 둜 μ„€μ •μ‹œ, 2 초짜리 μ• λ‹ˆλ©”μ΄μ…˜μ€ 1μ΄ˆλΆ€ν„° μ‹œμž‘ν•¨


animation-iteration-count#

μ• λ‹ˆλ©”μ΄μ…˜μ˜ 반볡 횟수λ₯Ό μ„€μ • - κ°œλ³„ 속성


속성 κ°’#

κ°’μ˜λ―ΈκΈ°λ³Έκ°’
숫자반볡 횟수λ₯Ό μ„€μ •1
infiniteλ¬΄ν•œ 반볡

animation-direction#

μ• λ‹ˆλ©”μ΄μ…˜μ˜ 반볡 λ°©ν–₯을 μ„€μ • - κ°œλ³„ 속성


속성 κ°’#

κ°’μ˜λ―ΈκΈ°λ³Έκ°’
normalμ •λ°©ν–₯만 반볡normal
reverseμ—­λ°©ν–₯만 반볡
alternateμ •λ°©ν–₯μ—μ„œ μ—­λ°©ν–₯으둜 반볡(왕볡)
alternate-reverseμ—­λ°©ν–₯μ—μ„œ μ •λ°©ν–₯으둜 반볡(왕볡)

animation-fill-mode#

μ• λ‹ˆλ©”μ΄μ…˜μ˜ μ „ν›„ μƒνƒœ(μœ„μΉ˜)λ₯Ό μ„€μ • - κ°œλ³„ 속성


속성 κ°’#

κ°’μ˜λ―ΈκΈ°λ³Έκ°’
noneκΈ°μ‘΄ μœ„μΉ˜μ—μ„œ μ‹œμž‘ -> μ• λ‹ˆλ©”μ΄μ…˜ μ‹œμž‘ μœ„μΉ˜λ‘œ 이동 -> λ™μž‘ -> κΈ°μ‘΄ μœ„μΉ˜μ—μ„œ 끝none
forwardsκΈ°μ‘΄ μœ„μΉ˜μ—μ„œ μ‹œμž‘ -> μ• λ‹ˆλ©”μ΄μ…˜ μ‹œμž‘ μœ„μΉ˜λ‘œ 이동 -> λ™μž‘ -> μ• λ‹ˆλ©”μ΄μ…˜ 끝 μœ„μΉ˜μ—μ„œ 끝
backwardsμ• λ‹ˆλ©”μ΄μ…˜ μ‹œμž‘ μœ„μΉ˜μ—μ„œ μ‹œμž‘ -> λ™μž‘ -> κΈ°μ‘΄ μœ„μΉ˜μ—μ„œ 끝
bothμ• λ‹ˆλ©”μ΄μ…˜ μ‹œμž‘ μœ„μΉ˜μ—μ„œ μ‹œμž‘ -> λ™μž‘ -> μ• λ‹ˆλ©”μ΄μ…˜ 끝 μœ„μΉ˜μ—μ„œ 끝

πŸ”— animation-fill-mode by park young woong


animation-play-state#

μ• λ‹ˆλ©”μ΄μ…˜μ˜ μž¬μƒκ³Ό 정지λ₯Ό μ„€μ • - κ°œλ³„ 속성

κ°’μ˜λ―ΈκΈ°λ³Έκ°’
runningμ• λ‹ˆλ©”μ΄μ…˜μ„ λ™μž‘running
pausedμ• λ‹ˆλ©”μ΄μ…˜ λ™μž‘μ„ 정지

Reference#

패슀트캠퍼슀 - ν”„λ‘ νŠΈμ—”λ“œ 개발 κ°•μ˜ - HTML & CSS, SASS(SCSS) Part by ParkYoungWoong