1 Star 0 Fork 0

zz/ web

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
js20230322work.html 1.37 KB
一键复制 编辑 原始数据 按行查看 历史
zz 提交于 2023-03-22 21:36 . 11
<!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>
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/z439442/web.git
git@gitee.com:z439442/web.git
z439442
web
web
master

搜索帮助

0d507c66 1850385 C8b1a773 1850385