为了账号安全,请及时绑定邮箱和手机立即绑定

贪吃蛇代码case37等代码打完后方向键却没有让方块移动,我的代码有何问题?

贪吃蛇代码case37等代码打完后方向键却没有让方块移动,我的代码有何问题?

慕粉1196024 2020-02-22 14:19:24
<!DOCTYPE html><html lang="en"><head>    <meta charset="UTF-8">    <title>Document</title></head><style>#container div{position: absolute;left: 0px;top: 0px;width: 50px;height: 50px;background: blue;opacity: 0.5px;text-align: center;line-height: 50px;font-size: 24px;color: #fff;   }</style><body>    <div id="container">        <div>1</div>        <div>2</div>        <div>3</div>        <div>4</div>    </div>    <script>        var container = document.getElementById("container"),        oDiv = container.getElementsByTagName("div")        width = oDiv[0].offsetWidth;        for(var i=oDiv.length-1;1>=0;i--){            oDiv[i].style.left = (oDiv.length-1-i)*50+"px";        }        document.onkeydown = function(e){            var e = window.event || e;            switch(e.keyCode){                case 37:                oDiv[0].style.left = oDiv[0].offsetLeft-width+"px";                break;                case 38:                oDiv[0].style.top = oDiv[0].offsetTop-width+"px";                break;                case 39:                oDiv[0].style.left = oDiv[0].offsetLeft+width+"px";                break;                case 40:                oDiv[0].style.top = oDiv[0].offsetTop+width+"px";                break;            }        }    </script></body></html>
查看完整描述

目前暂无任何回答

  • 0 回答
  • 0 关注
  • 665 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信