2022 SW전문인재양성사업/웹 퍼블리싱

CSS 기초 (2) - transition

마루설아 2022. 7. 26. 19:06
<!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>Document</title>
    <style>
        body{
            background-color: navy;
        }

        #box{
            background-color: red;
            width: 100px;
            height: 100px;
            border: 5px solid orange;
            border-radius: 12px;
            transition: width 2s cubic-bezier(1,1.72,0,-0.39), 
                left 2s cubic-bezier(.79,-0.39,.79,1.63);
            
            position: relative;
            left: 0px;
        }
    </style>
</head>
<body>
    <button id="goBtn">Go</button>
    <hr />
    <div id="box">Box</div>

    <script>
        // DOM - Document Object Model
        let goBtn = document.getElementById("goBtn");
        let box = document.getElementById("box");
        console.log(goBtn);
        console.dir(box);
        console.dir(goBtn);

        goBtn.style.backgroundColor = "Yellow";
        goBtn.style.height = "40px";
        goBtn.style.width = "60px";

        // goBtn 클릭하면 box속성 변경
        goBtn.onclick = function() {
            box.style.width = "150px";
            box.style.left = "400px";
        };

        goBtn.onmouseout = function() {
            box.style.width = "100px";
            box.style.left = "0";
        };

    </script>
</body>
</html>