λ³Έλ¬Έ λ°”λ‘œκ°€κΈ°
κ°œμΈκ³΅λΆ€/HTML5 + CSS3

[HTML+CSS][CSS3와 μ• λ‹ˆλ©”μ΄μ…˜] 04 - μ• λ‹ˆλ©”μ΄μ…˜

by πŸ‡λ°•λ΄‰λ΄‰πŸ‡ 2020. 8. 12.

 

 

 

[HTML+CSS][CSS3와 μ• λ‹ˆλ©”μ΄μ…˜] 03 - νŠΈλžœμ§€μ…˜

[HTML+CSS][CSS3와 μ• λ‹ˆλ©”μ΄μ…˜] 02 - λ³€ν˜•κ³Ό κ΄€λ ¨λœ 속성듀 [HTML+CSS][CSS3와 μ• λ‹ˆλ©”μ΄μ…˜] 01 - λ³€ν˜• [HTML+CSS][λ‹€μž¬λ‹€λŠ₯ν•œ CSS3 μ„ νƒμž] 03 - 가상 ν΄λž˜μŠ€μ™€ 가상 μš”μ†Œ [HTML+CSS][λ‹€μž¬λ‹€λŠ₯ν•œ CSS3 μ„ νƒμž] 02..

onelight-stay.tistory.com

 

νŠΈλžœμ§€μ…˜μ„ 보닀 더 λΆ€λ“œλŸ½κ³ 

μ‰½κ²Œ μ‚¬μš©ν•  수 μžˆλŠ”

μ• λ‹ˆλ©”μ΄μ…˜μ— λŒ€ν•΄μ„œ μ•Œμ•„λ³΄μž.

 

 


 

 

CSS와 μ• λ‹ˆλ©”μ΄μ…˜

 

μ• λ‹ˆλ©”μ΄μ…˜μ€ μ‹œμž‘ μŠ€νƒ€μΌκ³Ό λ μŠ€νƒ€μΌμ„ μ§€μ •ν•˜λ©΄ 

CSSμ—μ„œ μ€‘κ°„ μŠ€νƒ€μΌμ„ μžλ™μœΌλ‘œ μΆ”κ°€ν•΄ 

μ „μ²΄μ μœΌλ‘œ λΆ€λ“œλŸ½κ²Œ λ³€ν•˜λŠ” μ• λ‹ˆλ©”μ΄μ…˜ νš¨κ³Όλ₯Ό λ§Œλ“€μ–΄ λ‚Έλ‹€λŠ” 

νŠΈλžœμ§€μ…˜κ³Ό λΉ„μŠ·ν•œ μ„±κ²©μ„ κ°€μ§€κ³  μžˆκΈ΄ ν•˜μ§€λ§Œ,
CSS μ• λ‹ˆλ©”μ΄μ…˜μ€ μ‹œμž‘ν•΄ λλ‚΄λŠ” λ™μ•ˆ μ›ν•˜λŠ” κ³³ μ–΄λ””μ„œλ“  μŠ€νƒ€μΌμ„ λ°”κΎΈλ©° 

μ• λ‹ˆλ©”μ΄μ…˜μ„ μ •μ˜ν•  수 μžˆλ‹€λŠ” 차이점이 μžˆλ‹€.

 

 

μ΄λ•Œ, μ• λ‹ˆλ©”μ΄μ…˜ 쀑간에 μŠ€νƒ€μΌμ΄ λ°”λ€ŒλŠ” 지점을 

'ν‚€ν”„λ ˆμž„(keyframe)이라고 ν•œλ‹€.

 

 

CSS μ• λ‹ˆλ©”μ΄μ…˜μ—μ„œ μ‚¬μš©ν•˜λŠ” 속성

μ• λ‹ˆλ©”μ΄μ…˜μ€ μ΄μ „ λͺ¨λ˜ λΈŒλΌμš°μ €λ₯Ό κ³ λ €ν•΄ 

-webkit-, -moz-, -o- μ ‘두사λ₯Ό λΆ™μ—¬μ„œ μ‚¬μš©ν•œλ‹€.

 

 


 

@keyframes 속성 : μ• λ‹ˆλ©”μ΄μ…˜ 지정 μ„€μ •

 

μ• λ‹ˆλ©”μ΄μ…˜μ˜ μ‹œμž‘κ³Ό 끝을 λΉ„λ‘―ν•΄ μƒνƒœκ°€ λ°”λ€ŒλŠ” 뢀뢄이 μžˆμ„ 경우

ν•΄λ‹Ή 속성을 μ΄μš©ν•΄ λ°”λ€ŒλŠ” 지점을 μ„€μ •ν•˜λŠ” κ²ƒμœΌλ‘œ
λ¨Όμ € μ›Ή λ¬Έμ„œμ—μ„œ μ—¬λŸ¬ μ• λ‹ˆλ©”μ΄μ…˜μ„ μ •μ˜ν•  κ²ƒμ„ λŒ€λΉ„ν•΄ 

'이름'으둜 μ• λ‹ˆλ©”μ΄μ…˜μ„ κ΅¬λ³„ν•΄μ€€ λ’€μ— 

μŠ€νƒ€μΌ 속성 값이 λ°”λ€ŒλŠ” μ§€μ μ„ 'μ„ νƒμž'둜 μž…λ ₯ν•΄ μ£Όλ©΄ λœλ‹€.

 

 

<!DOCTYPE html>
<html lang="ko">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>@keyframes</title>
    <style>
        div {
            width: 100px;
            height: 100px;
            background-color: blue;
            border: 2px black solid;
            -webkit-animation-name: change-bg;
            -moz-animation-name: change-bg;
            -o-animation-name: change-bg;
            animation-name: change-bg;
            -webkit-animation-duration: 3s;
            -moz-animation-duration: 3s;
            -o-animation-duration: 3s;
            animation-duration: 3s;
        }
        @-webkit-keyframes change-bg {
            from {
                background-color: blue;
            }
            to {
                background-color: cornflowerblue;
                border-radius: 50%;
            }
        }
        @-moz-keyframes change-bg {
            from {
                background-color: blue;
            }
            to {
                background-color: cornflowerblue;
                border-radius: 50%;
            }
        }
        @-o-keyframes change-bg {
            from {
                background-color: blue;
            }
            to {
                background-color: cornflowerblue;
                border-radius: 50%;
            }
        }
        @keyframes change-bg {
            from { /* μ• λ‹ˆλ©”μ΄μ…˜ μ‹œμž‘ μ‹œμ  */
                background-color: blue;
            }
            to { /* μ• λ‹ˆλ©”μ΄μ…˜ 끝 μ‹œμ  */
                background-color: cornflowerblue;
                border-radius: 50%;
            }
        }
    </style>
</head>
<body>
    <h3>μ‚¬κ°ν˜•μ—μ„œ μ›μœΌλ‘œ μ„œμ„œνžˆ λ°”λ€ŒλŠ” μ• λ‹ˆλ©”μ΄μ…˜</h3>
    <div></div>
</body>
</html>

 

 


 

 

animation-name 속성 : μ• λ‹ˆλ©”μ΄μ…˜ 이름 지정

 

μ• λ‹ˆλ©”μ΄μ…˜μ„ μ΄λ¦„μœΌλ‘œ κ΅¬λΆ„ν•˜κΈ° μœ„ν•΄ μ‚¬μš©ν•˜λŠ” μ†μ„±μœΌλ‘œ 

λΈŒλΌμš°μ € μ ‘두사λ₯Ό λΆ™μ—¬ μ‚¬μš©ν•œλ‹€.

 

 

<!DOCTYPE html>
<html lang="ko">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>animation-name</title>
    <style>
        div {
            width: 200px;
            height: 200px;
            border: black 2px solid;
            float: left;
            margin: 35px;
        }
        #box1 {
            background-color: greenyellow;
            -webkit-animation-name: shape;
            -moz-animation-name: shape;
            -o-animation-name: shape;
            animation-name: shape;
            -webkit-animation-duration: 3s;
            -moz-animation-duration: 3s;
            -o-animation-duration: 3s;
            animation-duration: 3s;
        }
        #box2 {
            background-color: violet;
            -webkit-animation-name: rotate;
            -moz-animation-name: rotate;
            -o-animation-name: rotate;
            animation-name: rotate;
            -webkit-animation-duration: 3s;
            -moz-animation-duration: 3s;
            -o-animation-duration: 3s;
            animation-duration: 3s;
        }
        @-webkit-keyframes shape {
            form {border-radius: 0%;}
            to {border-radius: 50%;}
        }
        @-moz-keyframes shape {
            form {border-radius: 0%;}
            to {border-radius: 50%;}
        }
        @-o-keyframes shape {
            form {border-radius: 0%;}
            to {border-radius: 50%;}
        }
        @keyframes shape {
            form {border-radius: 0%;}
            to {border-radius: 50%;}
        }
        @-o-keyframes rotate {
            form {
                -webkit-transform: rotate(0deg);
                -moz-transform: rotate(0deg);
                -o-transform: rotate(0deg);
                -ms-transform: rotate(0deg);
                transform: rotate(0deg);
            }
            to {
                -webkit-transform: rotate(45deg);
                -moz-transform: rotate(45deg);
                -o-transform: rotate(45deg);
                -ms-transform: rotate(45deg);
                transform: rotate(45deg);
            }
        }
        @-moz-keyframes rotate {
            form {
                -webkit-transform: rotate(0deg);
                -moz-transform: rotate(0deg);
                -o-transform: rotate(0deg);
                -ms-transform: rotate(0deg);
                transform: rotate(0deg);
            }
            to {
                -webkit-transform: rotate(45deg);
                -moz-transform: rotate(45deg);
                -o-transform: rotate(45deg);
                -ms-transform: rotate(45deg);
                transform: rotate(45deg);
            }
        }
        @-webkit-keyframes rotate {
            form {
                -webkit-transform: rotate(0deg);
                -moz-transform: rotate(0deg);
                -o-transform: rotate(0deg);
                -ms-transform: rotate(0deg);
                transform: rotate(0deg);
            }
            to {
                -webkit-transform: rotate(45deg);
                -moz-transform: rotate(45deg);
                -o-transform: rotate(45deg);
                -ms-transform: rotate(45deg);
                transform: rotate(45deg);
            }
        }
        @keyframes rotate {
            form {
                -webkit-transform: rotate(0deg);
                -moz-transform: rotate(0deg);
                -o-transform: rotate(0deg);
                -ms-transform: rotate(0deg);
                transform: rotate(0deg);
            }
            to {
                -webkit-transform: rotate(45deg);
                -moz-transform: rotate(45deg);
                -o-transform: rotate(45deg);
                -ms-transform: rotate(45deg);
                transform: rotate(45deg);
            }
        }
    </style>
</head>
<body>
    <h3>@keyframe을 μ‚¬μš©ν•΄ μ‹€ν–‰ν•  μ• λ‹ˆλ©”μ΄μ…˜ μ§€μ •ν•˜κΈ°</h3>
    <div id="box1"></div>
    <div id="box2"></div>
</body>
</html>

 

 


 

 

animation-duration 속성 : μ• λ‹ˆλ©”μ΄μ…˜ μ‹€ν–‰μ‹œκ°„ μ„€μ •

 

μ• λ‹ˆλ©”μ΄μ…˜μ΄ μ–Όλ§ˆ λ™μ•ˆ μž¬μƒν•  것인지λ₯Ό μ„€μ •ν•˜λŠ” 것이닀.

 

 


 

 

animation-direction 속성 : μ• λ‹ˆλ©”μ΄μ…˜ λ°©ν–₯ 지정

 

μ• λ‹ˆλ©”μ΄μ…˜μ΄ λλ‚œ ν›„μ˜ μ„€μ •μ„ λ°”κΏ”μ„œ μ‚¬μš©ν•˜λŠ” κ²ƒμœΌλ‘œ
μ• λ‹ˆλ©”μ΄μ…˜μ΄ ν•œ λ²ˆ μ‹€ν–‰λ˜λ©΄ μ›λž˜ μœ„μΉ˜λ‘œ λ˜λŒμ•„ κ°€κ²Œ λ˜λŠ”데
μ΄λ•Œ μ›λž˜λŒ€λ‘œ λ˜λŒμ•„κ°€κ±°λ‚˜ λ°˜λŒ€ λ°©ν–₯으둜 μ• λ‹ˆλ©”μ΄μ…˜μ„ ν•œ λ²ˆ λ” μ‹€ν–‰ν•  μˆ˜ μžˆλ‹€.

 

 


 

 

animation-iteration-count 속성 : 반볡 횟수 지정

 

 

 

<!DOCTYPE html>
<html lang="ko">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>animation-iteration-count</title>
    <style>
        .box {
            margin-top: 50px;
            margin-left: 100px;
            padding: 20px;
            height: 60px;
            -webkit-animation-name: move;
            -moz-animation-name: move;
            -o-animation-name: move;
            animation-name: move;
            -webkit-animation-duration: 3s;
            -moz-animation-duration: 3s;
            -o-animation-duration: 3s;
            animation-duration: 3s;
            -webkit-animation-direction: normal;
            -moz-animation-direction: normal;
            -o-animation-direction: normal;
            animation-direction: normal;
            -webkit-animation-iteration-count: infinite;
            -moz-animation-iteration-count: infinite;
            -o-animation-iteration-count: infinite;
            animation-iteration-count: infinite;
        }
        @-webkit-keyframes move {
            from {
                width: 200px;
                background-color: wheat;
                opacity: 0.5;
                transform: rotate(150deg) scale(0.5);
            }
            to {
			    width: 400px;
			    background: #ff9400;
			    opacity: 1;
			    transform: scale(1) rotate(0deg);
		    }
        }
        @-moz-keyframes move {
            from {
                width: 200px;
                background-color: wheat;
                opacity: 0.5;
                transform: rotate(150deg) scale(0.5);
            }
            to {
			    width: 400px;
			    background: #ff9400;
			    opacity: 1;
			    transform: scale(1) rotate(0deg);
		    }
        }
        @-o-keyframes move {
            from {
                width: 200px;
                background-color: wheat;
                opacity: 0.5;
                transform: rotate(150deg) scale(0.5);
            }
            to {
			    width: 400px;
			    background: #ff9400;
			    opacity: 1;
			    transform: scale(1) rotate(0deg);
		    }
        }
        @keyframes move {
            from {
                width: 200px;
                background-color: wheat;
                opacity: 0.5;
                transform: rotate(150deg) scale(0.5);
            }
            to {
			    width: 400px;
			    background: #ff9400;
			    opacity: 1;
			    transform: scale(1) rotate(0deg);
		    }
        }
    </style>
</head>
<body>
    <h3>λ¬΄ν•œ λ°˜λ³΅ν•˜λŠ” μ• λ‹ˆλ©”μ΄μ…˜ λ§Œλ“€κΈ°</h3>
    <div class="box"><h3>CSS3 Animation</h3></div>
</body>
</html>

 

 


 

 

animation-timing-function 속성 : μ• λ‹ˆλ©”μ΄μ…˜ 속도 곑선

 

μ• λ‹ˆλ©”μ΄μ…˜μ˜ μ‹œμž‘κ³Ό 쀑간, λμ—μ„œμ˜

속도λ₯Ό 선택해 속도 곑선을 μ§€μ •ν•˜λŠ” 것이닀.

 

 


 

 

animation 속성 : μ• λ‹ˆλ©”μ΄μ…˜ κ΄€λ ¨ 속성 ν•œκΊΌλ²ˆμ— ν‘œκΈ°

 

κΈΈκ³  λ³΅μž‘ν•œ μ• λ‹ˆλ©”μ΄μ…˜ κ΄€λ ¨ μ†μ„±λ“€μ„ κ°„λ‹¨νžˆ ν•œ μ€„λ‘œ ν‘œν˜„ν•˜λŠ” μ†μ„±μ΄λ‹€.


κΈ°λ³Έν˜•μ— λ‚˜μ—΄λœ μ†μ„± μˆœμ„œλŠ” μ€‘μš”ν•˜μ§€ μ•Šμ§€λ§Œ 

μ‹œκ°„ κ°’이 λ‘ κ°œλΌλ©΄ μ²« λ²ˆμ§Έ μ‹œκ°„μœΌλ‘œ <animation-time>,
두 번째 μ‹œκ°„은 <animation-delay> μ†μ„±μœΌλ‘œ κ°„μ£Όν•œλ‹€.

 

 

<!DOCTYPE html>
<html lang="ko">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>animation</title>
    <style>
        .box {
            width: 100px;
            height: 100px;
            margin: 70px;
            -webkit-animation: rotate 1.5s infinite, background 1.5s infinite alternate;
            -moz-animation: rotate 1.5s infinite, background 1.5s infinite alternate;
            -o-animation: rotate 1.5s infinite, background 1.5s infinite alternate;
            animation: rotate 1.5s infinite, background 1.5s infinite alternate;
        }
        @-webkit-keyframes rotate {
            from {
                transform: perspective(120px) rotateX(0deg) rotateY(0deg);
            }
            50% {
                transform: perspective(120px) rotateX(-180deg) rotateY(0deg);
            }
            to {
                transform: perspective(120px) rotateX(-180deg) rotateY(-180deg);
            }
        }
        @-moz-keyframes rotate {
            from {
                transform: perspective(120px) rotateX(0deg) rotateY(0deg);
            }
            50% {
                transform: perspective(120px) rotateX(-180deg) rotateY(0deg);
            }
            to {
                transform: perspective(120px) rotateX(-180deg) rotateY(-180deg);
            }
        }
        @-o-keyframes rotate {
            from {
                transform: perspective(120px) rotateX(0deg) rotateY(0deg);
            }
            50% {
                transform: perspective(120px) rotateX(-180deg) rotateY(0deg);
            }
            to {
                transform: perspective(120px) rotateX(-180deg) rotateY(-180deg);
            }
        }
        @keyframes rotate {
            from {
                transform: perspective(120px) rotateX(0deg) rotateY(0deg);
            }
            50% {
                transform: perspective(120px) rotateX(-180deg) rotateY(0deg);
            }
            to {
                transform: perspective(120px) rotateX(-180deg) rotateY(-180deg);
            }
        }
        @-webkit-keyframes background {
            from { background: red;}
            50% {background: green;}
            to {background: blue;}
        }
        @-moz-keyframes background {
            from { background: red;}
            50% {background: green;}
            to {background: blue;}
        }
        @-o-keyframes background {
            from { background: red;}
            50% {background: green;}
            to {background: blue;}
        }
        @keyframes background {
            from { background: red;}
            50% {background: green;}
            to {background: blue;}
        }
    </style>
</head>
<body>
    <h3>두 개 μ΄μƒμ˜ μ• λ‹ˆλ©”μ΄μ…˜ λ™μ‹œμ— μ‹€ν–‰ν•˜κΈ°</h3>
    <div class="box"></div>
</body>
</html>

 

 


 

 

νš¨κ³Όκ°€ ν™•μ—°ν•˜κ²Œ λ“œλŸ¬λ‚˜λŠ” 만큼

μ‚¬μš©ν•˜λŠ” μ½”λ“œμ™€ μ ‘λ‘μ‚¬μ˜ 양이 λ§Žμ•„μ§€λŠ” 것 κ°™λ‹€.

 

가급적 animation 속성을 μ‚¬μš©ν•΄ ν•œκΊΌλ²ˆμ— ν‘œκΈ°ν•΄μ•Ό κ² λ‹€.

 

 


 

 

< μ°Έκ³  >

Do it! HTML5+CSS3 μ›Ή ν‘œμ€€μ˜ 정석

 

 

β€» ν•΄λ‹Ή 글은 μŠ΅λ“ λͺ©μ μœΌλ‘œ μž‘μ„±λœ κΈ€μž…λ‹ˆλ‹€ β€»

 

λ°˜μ‘ν˜•

λŒ“κΈ€