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>
版权声明:本文标题:移动盒子 【源代码】 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://m.elefans.com/xitong/1727501031a1118004.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论