admin管理员组

文章数量:1563235

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <link rel="stylesheet" href="css/index.css">
    <style>
        .box {
            position: absolute;
            left: 0;
            top: 0;
            width: 100px;
            height: 100px;
            background-color: green;
        }
    </style>
</head>

<body>
    <div class="box"></div>
    <script src="js/utils.js"></script>
    <script>
        var box = document.getElementsByClassName('box')[0];

        document.onkeydown = function (e) {
            var e = e || window.event,
                code = e.keyCode,
                bLeft = getStyles(box, 'left'),
                bTop = getStyles(box, 'top');

            switch (code) {
                case 37:
                    box.style.left = bLeft - 5 + 'px';
                    break;
                case 39:
                    box.style.left = bLeft + 5 + 'px';
                    break;
                case 38:
                    box.style.top = bTop - 5 + 'px';
                    break;
                case 40:
                    box.style.top = bTop + 5 + 'px';
                    break;
                default:
                    break;
            }
        }
    </script>
</body>

</html>

本文标签: 源代码盒子