<!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>根据键盘去控制div的移动</title>
<style>
*{
margin: 0;
padding: 0;
}
div{
width: 100px;
height: 100px;
background-color: hotpink;
position: absolute;
}
</style>
</head>
<body>
<div></div>
</body>
<script>
var d=document.querySelector('div')
// 状态加计时器
var timer=null;
var isLeft=false;
var isRight=false;
var isTop=false;
var isBottom=false;
window.onkeydown=function(e){
if(e.keyCode===37){
根据键盘去控制div的移动
最新推荐文章于 2024-06-08 10:27:47 发布