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

animation left / transform μ„±λŠ₯

by frontChoi 2023. 6. 12.
λ°˜μ‘ν˜•

πŸ“Ί  left / transform 차이

κΈ°νšμžλ‚˜ λ””μžμ΄λ„ˆ μš”κ΅¬μ‚¬ν•­μ— 따라 μ• λ‹ˆλ§€μ΄μ…˜μ„ λ„£μ–΄μ•Ό ν•˜λŠ” κ²½μš°κ°€ μžˆλ‹€. μ΄λ²ˆμ— μ• λ‹ˆλ©”μ΄μ…˜μ΄ λ²„λ²…μΈλ‹€λŠ” 말이 λ‚˜μ™”κ³ , μ• λ‹ˆλ©”μ΄μ…˜μ— 속도 μ €ν•˜μ‹œν‚€λŠ” μš”μ†Œκ°€ leftμ˜€λ‹€λŠ” 것을 λ°œκ²¬ν•˜μ˜€λ‹€.

 

κ°„λ‹¨ν•˜κ²Œ leftκ°€  0 => 100px ν•˜λŠ” λͺ¨μŠ΅μ„ λ§Œλ“€μ–΄λ³΄μ•˜λ‹€.

 

πŸ•ΉοΈ leftλ₯Ό μ΄μš©ν•œ μ• λ‹ˆλ©”μ΄μ…˜

left μ• λ‹ˆλ§€μ΄μ…˜

μœ„μ™€ 같이 λ§Œλ“€μ—ˆμ„λ•Œμ˜ 단점이 μ‘΄μž¬ν•˜μ˜€λ‹€. 단점은 μ• λ‹ˆλ©”μ΄μ…˜μ„ infinite(λ¬΄ν•œλ°˜λ³΅) μ‹œμΌ°μ„λ•Œ λ¦¬λ Œλ”λ§μ΄ 되고 μžˆμ—ˆλ‹€.

left λ Œλ”λ§

 

κ°„λ‹¨ν•œ leftλ₯Ό μ΄μš©ν•œ css μ½”λ“œμ΄λ‹€.

 

html

<!DOCTYPE html>
<html lang="en">

<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>Animation1</title>
    <link rel="stylesheet" href="./src/styles/animation1.css">
</head>

<body>
    <div class="container">
        <div class="circle left-animation">

        </div>
    </div>


</body>

</html>

css

.container {
    position: relative;
    display: inline-block;
    width: 100%;
    height: 100px;
}

.circle {
    display: inline-block;
    width: 100px;
    height: 100px;
    background-color: aqua;
    border-radius: 50%;
    position: absolute;
    left: 0;
    top: 0;
}


.left-animation {
    animation-delay: 250ms;
    animation-direction: normal;
    animation-duration: 3s;
    animation-iteration-count: infinite;
    animation-name: leftanimation;
}


@keyframes leftanimation {
    from {
        left: 0;
    }

    to {
        left: 100px;
    }
}

πŸͺ™ transform을 μ΄μš©ν•œ μ• λ‹ˆλ©”μ΄μ…˜

μ΄λ²ˆμ—λŠ” transform을 μ΄μš©ν•˜μ—¬ μ• λ‹ˆλ§€μ΄μ…˜μ„ λ§Œλ“€μ–΄λ³΄μ•˜λ‹€.

transform
transform_perfomance

μ•„λž˜λŠ” transform을 μ΄μš©ν•œ html,css μ½”λ“œμ΄λ‹€

 

html

<!DOCTYPE html>
<html lang="en">

<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>Animation1</title>
    <link rel="stylesheet" href="./src/styles/animation1.css">
</head>

<body>

    <div class="container">
        <div class="circle2 transform-animation">

        </div>
    </div>


</body>

</html>

css

.container {
    position: relative;
    display: inline-block;
    width: 100%;
    height: 100px;
}

.circle2 {
    display: inline-block;
    width: 100px;
    height: 100px;
    background-color: black;
    border-radius: 50%;
    position: absolute;
    top: 0;
    left: 0;
}

.transform-animation {
    animation-delay: 250ms;
    animation-direction: normal;
    animation-duration: 3s;
    animation-iteration-count: infinite;
    animation-name: transformanimation;
}

@keyframes transformanimation {
    from {
        transform: translateX(0);
    }

    to {
        transform: translateX(200px);
    }
}

 

 

⏱️ λ Œλ”λ§ 과정을 ν†΅ν•œ css μ„±λŠ₯ μ•ŒκΈ°

λ Œλ”λ§ 과정은  "νŒŒμ‹± = > λ ˆμ΄μ•„μ›ƒ => 페인트 => Composite"  μ΄ μΌμ–΄λ‚œλ‹€. μ—¬κΈ°μ„œ μ• λ‹ˆλ§€μ΄μ…˜μ—μ„œ "left" λ₯Ό μ‚¬μš©ν•œλ‹€λ©΄

"λ ˆμ΄μ•„μ›ƒ => 페인트 => Composite"이 λ°˜λ³΅ν•΄μ„œ μΌμ–΄λ‚œλ‹€. λ§Œμ•½ μ• λ‹ˆλ§€μ΄μ…˜μ„ λ¬΄ν•œλ°˜λ³΅(infinite) μ‹œν‚¬ κ²½μš°μ—λŠ” "λ ˆμ΄μ•„μ›ƒ => 페인트 => Composite" κ³„μ†ν•΄μ„œ λ¬΄ν•œλ°˜λ³΅ 과정이 μΌμ–΄λ‚˜λ©°, λΈŒλΌμš°μ € μ„±λŠ₯이 μ €ν•˜λ μˆ˜ μžˆλ‹€.

κ·ΈλŸ¬λ―€λ‘œ 가급적이면 μ• λ‹ˆλ§€μ΄μ…˜μ—μ„œλŠ” "left,top,width,height λ“±λ“±" 같은 속성 λ³΄λ‹€λŠ” "transform" 속성을 μ΄μš©ν•˜λŠ”κ²Œ λ‚«λ‹€

λ°˜μ‘ν˜•

'css' μΉ΄ν…Œκ³ λ¦¬μ˜ λ‹€λ₯Έ κΈ€

πŸ“« css animation μ„±λŠ₯ 비ꡐ  (5) 2023.06.22

λŒ“κΈ€