λ³Έλ¬Έ λ°”λ‘œκ°€κΈ°
CSS

CSS μ• λ‹ˆλ©”μ΄μ…˜ λ§Œλ“€κΈ° : λ‘œλ”© μ• λ‹ˆλ©”μ΄μ…˜

by μ½”νŒŒμΉ΄ 2022. 9. 24.
728x90

CSS μ• λ‹ˆλ©”μ΄μ…˜ : λ‘œλ”© μ• λ‹ˆλ©”μ΄μ…˜

μ˜€λŠ˜μ€ λ‘œλ”© ν™”λ©΄μ²˜λŸΌ λΉ™κΈ€λΉ™κΈ€ λŒμ•„κ°€λŠ” μ• λ‹ˆλ©”μ΄μ…˜μ„ λ§Œλ“€μ–΄ 보도둝 ν•˜κ² μŠ΅λ‹ˆλ‹€. μž‘μ—…ν•΄λ³Ό μ• λ‹ˆλ©”μ΄μ…˜μ€ λ‹€μŒκ³Ό κ°™μŠ΅λ‹ˆλ‹€.

See the Pen animation λͺ‡λ²ˆμ§Έμ§€... by mj0614k (@mj0614k) on CodePen.


1. HTML μ†ŒμŠ€

<div class="loader">
    <div class="ball"></div>
    <div class="ball"></div>
    <div class="ball"></div>
    <div class="ball"></div>
    <div class="ball"></div>
    <div class="ball"></div>
    <div class="ball"></div>
    <div class="ball"></div>
    <div class="ball"></div>
    <div class="ball"></div>
</div>

div μ•ˆμ— 10개의 div λ°•μŠ€λ₯Ό λ§Œλ“€μ–΄ μ€λ‹ˆλ‹€.

2. CSS μ†ŒμŠ€

body {
    background-color: pink;
}
    
.loader {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 100px;
    height: 100px;
    animation: spin 0.6s linear infinite reverse;
}
    
.ball {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    height: 100%;
    animation: spin 1s infinite ease-in-out;
}
    
.ball:after {
    position: absolute;
    content: '';
    background-color: #fff;
    width: 5px;
    height: 5px;
    border-radius: 100%;
    top: 0;
}
    
.ball:nth-child(2) {
    animation-delay: -0.1s;
}
.ball:nth-child(3) {
    animation-delay: -0.2s;
}
.ball:nth-child(4) {
    animation-delay: -0.3s;
}
.ball:nth-child(5) {
    animation-delay: -0.4s;
}
.ball:nth-child(6) {
    animation-delay: -0.5s;
}
.ball:nth-child(7) {
    animation-delay: -0.6s;
}
.ball:nth-child(8) {
    animation-delay: -0.7s;
}
.ball:nth-child(9) {
    animation-delay: -0.8s;
}
.ball:nth-child(10) {
    animation-delay: -0.9s;
}

@keyframes spin {
    0% {
        transform: translate(-50%, -50%) rotate(0deg)
    }
    100% {
        transform: translate(-50%, -50%) rotate(360deg)
    }
}

ball에 μ• λ‹ˆλ©”μ΄μ…˜ 효과λ₯Ό μ£Όκ³ , κ°€μƒμš”μ†Œλ„ λ§Œλ“€μ–΄ μ€λ‹ˆλ‹€. 각각의 ball에 순차적으둜 μ• λ‹ˆλ©”μ΄μ…˜ λ”œλ ˆμ΄λ₯Ό 0.1μ΄ˆμ”© λ„£μ–΄μ€λ‹ˆλ‹€. ballμ—μ„œ λ§Œλ“  μ• λ‹ˆλ©”μ΄μ…˜μ— keyframesλ₯Ό μ μš©ν•΄ μ€λ‹ˆλ‹€.

μœ„μ˜ HTML, CSS μ†ŒμŠ€λ₯Ό ν•©μΉ˜λ©΄ μ• λ‹ˆλ©”μ΄μ…˜μ΄ μ™„μ„±λ©λ‹ˆλ‹€. 예쁘죠?

728x90

λŒ“κΈ€

κ°μ‚¬ν•©λ‹ˆλ‹€. πŸ¦™

CSS
κ΄‘κ³  쀀비쀑