자바 스 크 립 트 div 마우스 수행

5642 단어 전단자바 script
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <style>
        .top{
            width: 50px;
            height: 50px;
            position: absolute;
            background-color: red;
        }
    </style>
    <script>
        window.onload = function () {
            var box = document.getElementsByClassName("top")[0];
            document.onmousemove = function (ev) {
                var ev = ev||window.event;
                var scrollleft = document.documentElement.scrollLeft || document.body.scrollLeft;
                var scrolltop = document.documentElement.scrollTop || document.body.scrollTop;
                box.style.left = ev.clientX +"px";
                box.style.top = ev.clientY + "px";
            }
        }
    </script>
</head>
<body>
<div class="top"></div>
</body>
</html>

좋은 웹페이지 즐겨찾기