ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • (HTML/CSS/JS) 간단한 이벤트 처리 해보기!
    HTML CSS JS 2021. 8. 11. 15:46

    - 추후 프로젝트에 메뉴바를 만들기 위해 메뉴바 실습을 해보기로 했다.

    - 메뉴바에 마우스를 올리면 메뉴바 색상, 글씨 크기, 굵기가 변경하게끔 이벤트 처리를 했다.

    - 메뉴바 크기가 천천히 길어지게끔 추가!

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    <!DOCTYPE html>
    <html>
    <head>
    <meta charset="UTF-8">
    <title>Insert title here</title>
     
    <style>
     
    div{
        width: 100px;
        height: 75px;
        background-color: coral;
        text-align: center;
        line-height: 75px;
        margin: 5px;
        font-size: 15px;
        transition: all 3s;
    }
     
    </style>
    </head>
    <body>
     
    <ul>
     
        <li><div class = 'menu'>상의</div></li>
        <li><div class = 'menu'>하의</div></li>
        <li><div class = 'menu'>신발</div></li>
        <li><div class = 'menu'>가방</div></li>
     
    </ul>
     
    <script type="text/javascript">
     
        var buttons = document.querySelectorAll('.menu');
        for(var button of buttons){
            button.onmouseover = function(){
                this.style.backgroundColor="aqua";
                this.style.fontSize = "20px";
                this.style.fontWeight = 'bolder';
                this.style.width = '50%';
            }
            button.onmouseout = function(){
                this.style.backgroundColor="coral";
                this.style.fontSize = "15px";
                this.style.fontWeight = 'normal';
                this.style.width = '20%';
            }
        }
     
    </script>
     
     
    </body>
    </html>
    cs
     

     

    기본 메뉴바

    - 마우스 올려서 바뀌는 것을 보여주고 싶은데 다음엔 짤로 만드는 법을 알아봐야겠다...

Designed by Tistory.