Menu



Manage

파일 목록
Study_Web > 4week/practice8-5.html Lines 47 | 1.3 KB
다운로드

                        <!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <title>z-index 스타일 프로퍼티</title>
    <style>
        div {
            position: absolute;
        }

        img {
            position: absolute;
        }
    </style>
</head>

<body>
    <h3>z-index 스타일 프로퍼티</h3>
    <hr>
    <div>
        <img src="C:/Users/remil/Desktop/spade-A.jpg" width="100" height="140" alt="스페이드A">
        <img src="C:/Users/remil/Desktop/spade-2.jpg" width="100" height="140" alt="스페이드2">
        <img src="C:/Users/remil/Desktop/spade-3.jpg" width="100" height="140" alt="스페이드3">
        <img src="C:/Users/remil/Desktop/spade-7.jpg" width="100" height="140" alt="스페이드7">
    </div>
    <script>
        let imgArray = document.getElementsByTagName("img");
        for (let i = 0; i < imgArray.length; i++) {
            let obj = imgArray[i];
            obj.style.zIndex = i;
            obj.style.left = "10px";
            obj.style.top = "20px";

            obj.onclick = shuffle;
        }
        function shuffle() {
            for (i = 0; i < imgArray.length; i++) {
                var obj = imgArray[i];
                obj.style.zIndex++;
                obj.style.zIndex %= imgArray.length;
            }
        }
    </script>
</body>

</html>