gpt4 book ai didi

javascript - 不能使物体移动。 Javascript

转载 作者:行者123 更新时间:2023-11-28 06:26:34 25 4
gpt4 key购买 nike

为此我使用了 YouTube 教程。我不明白为什么它不起作用。出于某种原因,当我按 AD 时没有任何反应。

<!DOCTYPE html>
<html>
<head>
<style type="text/css">
#container{
position: relative;
height: 600px;
width: 400px;
outline: 2px solid black;
}
#character{
position: absolute;
height: 50px;
width: 50px;
outline: 2px solid black;
background-color: #FF6600;
left: 0;
}
</style>
<body onkeydown="anim">
<div id="container">
<div id="character"></div>
</div>
<script>
var container = document.getElemnetById('container');
var character = document.getElemnetById('character');
var characterLeft = 0;
function anim(e){
if (e.keyCode == 97){
characterLeft += 2;
character.style.left = characterLeft + 'px';
}
if (e.keyCode == 100){
characterLeft -= 2;
character.style.left = characterLeft + 'px';
}
}
</script>
</body>
</head>
</html>

`

最佳答案

用这个

<div id="pop" onclick="anim();">
<span>click me</span>
<div id="container">
<div id="character">
</div>
</div>
<script>
var container = document.getElemnetById('container');
var character = document.getElemnetById('character');
var characterLeft = 0;
function anim()
{
alert('yes it work!!');

if (e.keyCode == 97){
characterLeft += 2;
character.style.left = characterLeft + 'px';
}
if (e.keyCode == 100){
characterLeft -= 2;
character.style.left = characterLeft + 'px';
}
}

</script>
</div>

关于javascript - 不能使物体移动。 Javascript,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35251937/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com