代码拉取完成,页面将自动刷新
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>周彬209020112</title>
<style type="text/css">
input{font-size:26px;margin-top: 20px;}
body{background-image: url(images/grassland.png);}
#mytank{position: absolute;left:10px;top:100px}
</style>
</head>
<body>
<img id="mytank" src="images/right.png"/>
<script>
const tank = document.getElementById("mytank");
let x = 10;
let y = 100;
let direction = "right";
document.addEventListener("keydown", (event) => {
if (event.key === "ArrowUp") {
y -= 10;
tank.style.top = `${y}px`;
direction = "up";
} else if (event.key === "ArrowDown") {
y += 10;
tank.style.top = `${y}px`;
direction = "down";
} else if (event.key === "ArrowLeft") {
x -= 10;
tank.style.left = `${x}px`;
direction = "left";
} else if (event.key === "ArrowRight") {
x += 10;
tank.style.left = `${x}px`;
direction = "right";
}
tank.src = `images/${direction}.png`;
});
document.addEventListener('contextmenu', event => {
event.preventDefault();
});
</script>
</body>
</html>
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。