🦁_21.11.09(2) TIL

BoriΒ·2021λ…„ 11μ›” 10일
0
post-thumbnail

21λ…„ 11μ›” 09일(2)

πŸ“ CSS

πŸ“Ž Animation

@Keyframes

  • νŠΉμ • λ³€ν™”κ°€ μΌμ–΄λ‚˜λŠ” 지점을 μ„€μ •ν•˜μ—¬ νŠΉμ • μ‹œκ°„ λ™μ•ˆ ν•΄λ‹Ή Property와 Valueλ₯Ό λ³€ν™”μ‹œν‚¨λ‹€.
  • @Keyframes at-rule 은 μ• λ‹ˆλ©”μ΄μ…˜ μ€‘κ°„μ€‘κ°„μ˜ νŠΉμ • 지점듀을 κ±°μΉ  수 μžˆλŠ” ν‚€ν”„λ ˆμž„λ“€μ„ μ„€μ •ν•˜μ—¬, CSS μ• λ‹ˆλ©”μ΄μ…˜ κ³Όμ •μ˜ 쀑간 λ™μž‘μ„ 보닀 더 μ„Έλ°€ν•˜κ²Œ μ œμ–΄ν•  수 있게 ν•œλ‹€.

transition vs animation 차이점

  • transition

    • 트리거 μš”μ†Œκ°€ ν•„μš”ν•˜λ‹€.
      => :hover, :focus λ“±
    • μ‹œμž‘ μƒνƒœμ™€ μ’…λ£Œ μƒνƒœ μ‚¬μ΄μ—μ„œ λ™μž‘
      => κ°„λ‹¨ν•œ μ• λ‹ˆλ©”μ΄μ…˜μ— μ‚¬μš©
      => button, dropdown menu λ“±
  • animation

    • μ‹œμž‘ μƒνƒœ/μ’…λ£Œ μƒνƒœμ— 관계없이 λ™μž‘ κ°€λŠ₯
      => 끝없이 λ™μž‘ κ°€λŠ₯, 경계가 μ—†μŒ
    • animation 속성은 @Keyframesλ₯Ό μ΄μš©ν•΄ ν”„λ ˆμž„ μΆ”κ°€ κ°€λŠ₯

@Keyframes κ·œμΉ™

  • @Keyframes κ·œμΉ™μ€ μ• λ‹ˆλ©”μ΄μ…˜ μ½”λ“œλ₯Ό μ§€μ •ν•œλ‹€.
  • μŠ€νƒ€μΌ λ³€κ²½ 지점은 λ°±λΆ„μœ¨λ‘œ 지정할 수 μžˆλ‹€.
    => from, to ν‚€μ›Œλ“œ μ‚¬μš© κ°€λŠ₯
  @keyframes animationname {
    keyframes-selector {
      css-styles;
    }
  }
animationnameμ• λ‹ˆλ©”μ΄μ…˜ 이름 μ •μ˜
keyframes-selector μ• λ‹ˆλ©”μ΄μ…˜ 지속 μ‹œκ°„μ˜ λ°±λΆ„μœ¨
κ°’ : 0%(from) -100%(to)
css-stylesCSS μŠ€νƒ€μΌ 속성 지정
@keyframes mymove {
  0%   {top: 0px; left: 0px; background: red;}
  25%  {top: 0px; left: 100px; background: blue;}
  50%  {top: 100px; left: 100px; background: yellow;}
  75%  {top: 100px; left: 0px; background: green;}
  100% {top: 0px; left: 0px; background: red;}
}

/* keyframes μ•ˆμ—μ„œ !importantλŠ” λ¬΄μ‹œλœλ‹€. */
@keyframes myexample {
  from {top: 0px;}
  50%  {top: 100px !important;} /* ignored */
  to   {top: 200px;}
}

Animation 적용

animation: name duration timing-function delay iteration-count direction fill-mode play-state;
  • animation은 단일 μ†μ„±λ“€μ˜ μΆ•μ•½ν˜•

    • animation-name : μ• λ‹ˆλ©”μ΄μ…˜μ„ ν˜ΈμΆœν•˜κΈ° μœ„ν•œ 이름
      => keyframes 이름과 동일

    • animation-duration : μ• λ‹ˆλ©”μ΄μ…˜μ˜ μ‹œμž‘λΆ€ν„° μ’…λ£ŒκΉŒμ§€ 총 지속 μ‹œκ°„ 지정
      => λ‹¨μœ„ : s, ms
      => μ–‘μˆ˜ κ°’λ§Œ κ°€λŠ₯
      => 0μ΄λ‚˜ 음수둜 μ§€μ •ν–ˆμ„ 경우 μ• λ‹ˆλ©”μ΄μ…˜μ΄ μ‹€ν–‰λ˜μ§€ μ•ŠλŠ”λ‹€.
      => transition-durationκ³Ό λΉ„μŠ·

    • animation-timing-function : μ• λ‹ˆλ©”μ΄μ…˜μ˜ μž¬μƒ 속도 쑰절
      => ease | linear | ease-in | ease-out | cubic-bezier(n, n, n, n) λ“±
      => transition-timing-functionκ³Ό λΉ„μŠ·

    • animation-delay : μ• λ‹ˆλ©”μ΄μ…˜ μ‹œμž‘μ„ μ§€μ—°μ‹œν‚€κ³  싢을 경우 지정
      => 0 | now : λ°”λ‘œ μž¬μƒ
      => 음수 : μ§€μ •λœ μ‹œκ°„μ΄ μ§€λ‚œ μ΄ν›„μ˜ ν”„λ ˆμž„λΆ€ν„° μ• λ‹ˆλ©”μ΄μ…˜ μ‹œμž‘

    • animation-iteration-count : μ• λ‹ˆλ©”μ΄μ…˜ μž¬μƒ 횟수 지정
      => κΈ°λ³Έ 값은 1
      => 0 | 음수 : μž¬μƒλ˜μ§€ μ•ŠμŒ
      => μ‹€μˆ˜ : μž¬μƒ 도쀑 첫 번째 ν”„λ ˆμž„μœΌλ‘œ λŒμ•„κ°€ μ’…λ£Œ
      => infinite : λ¬΄ν•œ 반볡

    • animation-direction : μ• λ‹ˆλ©”μ΄μ…˜μ˜ μž¬μƒ λ°©ν–₯ μ„€μ •
      => normal : 순방ν–₯ μž¬μƒ
      => reverse : μ—­λ°©ν–₯ μž¬μƒ
      => alternate : 순방ν–₯ μ‹œμž‘, μ—­λ°©ν–₯κ³Ό λ²ˆκ°ˆμ•„ μž¬μƒ
      => alternate-reverse : μ—­λ°©ν–₯ μ‹œμž‘, 순방ν–₯κ³Ό λ²ˆκ°ˆμ•„ μž¬μƒ

    • animation-fill-mode : μ• λ‹ˆλ©”μ΄μ…˜μ΄ μž¬μƒλ˜μ§€ μ•Šμ„ λ•Œ (μ‹œμž‘ μ „, μ’…λ£Œ ν›„ λ˜λŠ” λ‘˜ λ‹€) μš”μ†Œμ— λŒ€ν•œ μŠ€νƒ€μΌ 지정
      => none : κΈ°λ³Έκ°’, μŠ€νƒ€μΌμ„ μ μš©ν•˜μ§€ μ•ŠμŒ
      => forwards : λ§ˆμ§€λ§‰ ν‚€ν”„λ ˆμž„μ˜ μŠ€νƒ€μΌμ„ μœ μ§€, μ• λ‹ˆλ©”μ΄μ…˜ λ°©ν–₯μ΄λ‚˜ 반볡 νšŸμ‰ 따라 달라짐
      => backwards : 첫 번째 ν‚€ν”„λ ˆμž„μ˜ μŠ€νƒ€μΌ 값을 κ°€μ Έμ˜€κ³ , animation-delay λ™μ•ˆ 이 값을 μœ μ§€
      => both : forwards와 backwards의 κ·œμΉ™μ„ λ”°λ₯΄λ©° μ• λ‹ˆλ©”μ΄μ…˜ 속성을 μ–‘λ°©ν–₯으둜 ν™•μž₯

    • animation-play-state : μ• λ‹ˆλ©”μ΄μ…˜μ˜ μž¬μƒ μ—¬λΆ€ μ„€μ •
      => running : μž¬μƒ
      => paused : μΌμ‹œμ •μ§€

πŸ“Ž @Keyframes 예제

λΉŒλ”© 올리기


πŸ“Ž Perspective

  • perspective : 3D-positioned element에 원근법을 μ œκ³΅ν•˜κΈ° μœ„ν•΄ z=0 평면과 μ‚¬μš©μž μ‚¬μ΄μ˜ 거리λ₯Ό κ²°μ •
  /* Keyword value */
  perspective: none;

  /* <length> values */
  perspective: 20px;
  perspective: 3.5em;

  /* Global values */
  perspective: inherit;
  perspective: initial;
  perspecive: revert;
  perspective: unset;
noneperspective transfrom 이 μ μš©λ˜μ§€ μ•ŠμŒμ„ λ‚˜νƒ€λƒ„
<length>z=0 평면과 μ‚¬μš©μž μ‚¬μ΄μ˜ 거리λ₯Ό λ‚˜νƒ€λ‚΄λŠ” 길이

perspective-origin

  • perspective-origin : λ·°μ–΄κ°€ 보고 μžˆλŠ” μœ„μΉ˜λ₯Ό κ²°μ •
<!DOCTYPE html>
<html lang="ko">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>perspective</title>
    <style>
        .원본 {
            display: flex;
            justify-content: space-between;
            width: 1000px;
            height: 200px;
            border: 1px solid black;
            margin: 100px auto;
            perspective: 400px;
        }

        .νšŒμ „νŒ¨λ„ {
            width: 200px;
            height: 200px;
            background: aqua;
            transform: rotateY(45deg);
        }
    </style>
</head>
<body>
    <div class="원본">
        <div class="νšŒμ „νŒ¨λ„"></div>
        <div class="νšŒμ „νŒ¨λ„"></div>
        <div class="νšŒμ „νŒ¨λ„"></div>
        <div class="νšŒμ „νŒ¨λ„"></div>
        <div class="νšŒμ „νŒ¨λ„"></div>
        <div class="νšŒμ „νŒ¨λ„"></div>
    </div>
</body>
</html>

μœ„ 예제의 경우, 같은 κ°λ„λ‘œ μ›€μ§μ˜€λŠ”λ° μ™œ λ˜‘κ°™μ€ λ°•μŠ€λ‘œ λ‚˜μ˜€μ§€ μ•Šμ•˜μ„κΉŒ?

  • μ†Œμ‹€μ (vanishing point)이 λ‹€λ₯΄κΈ° λ•Œλ¬Έ
  • λΆ€λͺ¨κ°€ μ—¬λŸ¬ μžμ‹μ„ 가진 μƒνƒœμ—μ„œ μžμ‹μ—κ²Œ YμΆ• νšŒμ „μ„ μ‹œμΌ°μ„ λ•Œ λ°”λΌλ³΄λŠ” 화면은 정면이 μ•„λ‹ˆλΌ 우츑 쀑앙 기쀀이닀.

μΉ΄λ“œ 뒀집기 - μ†ŒμŠ€μ½”λ“œ 보기

  • transform-style : μš”μ†Œμ˜ μžμ‹ μš”μ†Œλ₯Ό 3D 곡간/평면 배치 μ—¬λΆ€ μ„€μ •, 이 속성은 μƒμ†λ˜μ§€ μ•ŠλŠ”λ‹€.

    κ°’μ„€λͺ…
    flatμš”μ†Œμ˜ μžμ‹ μš”μ†Œλ₯Ό μš”μ†Œ 자체의 평면에 배치
    preserve-3dμš”μ†Œμ˜ μžμ‹ μš”μ†Œλ₯Ό 3D 곡간에 배치
  /* Keyword values */
  transform-style: flat;
  transform-style: preserve-3d;

  /* Global values */
  transform-style: inherit;
  transform-style: initial;
  transform-style: revert;
  transform-style: unset;
  • backface-visibility : μš”μ†Œμ˜ 뒷면을 μ‚¬μš©μžκ°€ λ³Ό 수 μžˆλŠ”μ§€ μ—¬λΆ€ μ„€μ •
    μš”μ†Œμ˜ 뒷면은 μ•žλ©΄μ΄ 거울이 λΉ„μΉœ κ²ƒμ²˜λŸΌ 보인닀. 2Dμ—μ„œλŠ” 보이지 μ•Šμ§€λ§Œ transform으둜 μš”μ†Œκ°€ 3D κ³΅κ°„μ—μ„œ νšŒμ „ν•  λ•Œ 뒷면이 보일 수 μžˆλ‹€.

    κ°’μ„€λͺ…
    visibleμ‚¬μš©μž μͺ½μœΌλ‘œ λŒλ Έμ„ λ•Œ 뒷면이 λ³΄μž„
    hiddenμ‚¬μš©μžμ—κ²Œ 뒷면을 보이지 μ•Šκ²Œ 함
   /* Keyword values */
  backface-visibility: visible;
  backface-visibility: hidden;

  /* Global values */
  backface-visibility: inherit;
  backface-visibility: initial;
  backface-visibility: revert;
  backface-visibility: unset;

참고 링크


마무리

  • 수면 μ‹œκ°„ 잘 지킀기
    => μ•„μΉ¨λ§ˆλ‹€ 맀일 쑸리닀.
  • μˆ˜μ—… λ“€μœΌλ©΄μ„œ TIL μž‘μ„±μ„ ν•˜λ‹ˆκΉŒ μˆ˜μ—…μ‹œκ°„ λ‚΄λ‚΄ λ°”μ˜λ‹€.
    => κ·Έλž˜λ„ ν•˜λ£¨ μ•ˆμ— λ‹€ λͺ»μ λŠ” 쀑 히히
    => μž‘μ„±ν•  λ‚΄μš©μ΄ 점점 λ§Žμ•„μ§€λŠ” 것 κ°™λ‹€.
  • μ§‘μ—μ„œλ§Œ μˆ˜μ—… λ“£κΈ° λ‹΅λ‹΅ν•΄μ„œ μ μ‹¬μ‹œκ°„μ—λŠ” 카페둜 ν›„λ‹€λ‹₯
    => μ§‘μ—μ„œλŠ” μ‰¬λŠ” μ‹œκ°„λ§ˆλ‹€ λˆ„μ›Œλ²„λ¦¬λŠ”λ° μΉ΄νŽ˜μ—μ„œλŠ” μ‰¬λŠ” μ‹œκ°„μ—λ„ 계속 타이핑 타닀닀λ‹₯!
  • 였늘 배운 λ‚΄μš©λ“€μ€ μ•Œμ§€λ§Œ 잘 λͺ¨λ₯΄λŠ” λΆ€λΆ„μ΄μ—ˆλŠ”λ° TIL μž‘μ„±ν•˜λ©΄μ„œ MDN을 μ°Ύμ•„λ³΄λ‹ˆ 쑰금 더 μ•Œκ²Œ λ˜μ—ˆλ‹€.
    => MDN λ³΄λŠ”κ±° μ‹«μ–΄ν–ˆλŠ”λ° μͺΌκΈˆ μ μ‘ν–ˆλ‹€?!

0개의 λŒ“κΈ€