Menu



Manage

파일 목록
Study_Web > 5week/test9_10.html Lines 47 | 1.5 KB
다운로드

                        <!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>마우스 관련 리스너</title>
    <script>
        let width = 1; // 테두리 두께
        function down(obj) {
            obj.style.fontStyle = "italic";
        }
        function up(obj) {
            obj.style.fontStyle = "normal";
        }
        function over(obj) {
            obj.style.borderColor = "violet";
            // 테두리 폭이 0일 때 색은 보이지 않는다.
        }
        function out(obj) {
            obj.style.borderColor = "lightgray";
        }
        function wheel(e, obj) { // e는 이벤트 객체
            if (e.wheelDelta < 0) { // 휠을 아래로 굴릴 때
                width--; // 폭 1 감소
                if (width < 0) width = 0; // 폭이 0보다 작아지지 않게
            }
            else // 휠을 위로 굴릴 때
                width++; // 폭 1 증가
            obj.style.borderStyle = "ridge";
            obj.style.borderWidth = width + "px";
        }
    </script>
</head>

<body>
    <h3>마우스 관련 이벤트 리스너</h3>
    <hr>
    <div>마우스 관련
        <span onmousedown="down(this)" onmouseup="up(this)" onmouseover="over(this)" onmouseout="out(this)"
            onwheel="wheel(event, this)" style="display:inline-block">이벤트
        </span>가 발생합니다.
    </div>
</body>

</html>