1. 程式人生 > >js控制人物行走

js控制人物行走


<!DOCTYPE html>
<html>
<head runat="server">
    <title></title>

    <script type="text/javascript">
        x = 0;
        y = 600;
        function action(e) {
            o = document.getElementById("me");
            edsf = e.keyCode;
            if (edsf == 69) {
                y -= 10;
                o.style.marginTop = y + 'px';
            } else if (edsf == 68) {
                y += 10;
                o.style.marginTop = y + 'px';
            } else if (edsf == 83) {
                x -= 10;
                o.style.marginLeft = x + 'px';
            } else if (edsf == 70) {
                x += 10;
                o.style.marginLeft = x + 'px';
            } else if (edsf == 85) {
                o.src = "u.gif";
            } else if (edsf == 73) {

            } else if (edsf == 74) {

            } else if (edsf == 75) {

            }
        }
    
        
    </script>

</head>
<body onkeydown="action(event)" style="background-color: Lime;">
    <img id="me" src="me.gif" style="margin-top: 600px;" />
</body>
</html>