Не двигаются блоки, jquery
В чём ошибка ? Не двигаются блоки :-?
Помогите пожалуйста:yes: var pingpong = {} pingpong.pressedKeys = []; $(function(){ pingpong.timer = setInterval(gameloop,30); $(document).keydown(function(e){ pingpong.pressedKeys[e.which] = true; )}; $(document).keyup(function(e){ pingpong.pressedKeys[e.which] = false; )}; }); function gameloop(){ movePaddles(); } function movePaddles(){ if(pingpong.pressedKeys[KEY.UP]){ var top = parseInt($("#paddleB").css("top")); $("#paddleB").css("top",top-5); } if(pingpong.pressedKeys[KEY.DOWN]){ var top = parseInt($("#paddleB").css("top")); $("#paddleB").css("top",top+5); } if(pingpong.pressedKeys[KEY.W]){ var top = parseInt($("#paddleA").css("top")); $("#paddleA").css("top",top-5); } if(pingpong.pressedKeys[KEY.S]){ var top = parseInt($("#paddleA").css("top")); $("#paddleA").css("top",top+5); } } <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>Ping pong</title> <script src="jquery-1.4.4.min.js"></script> <script src="pingpong.js"></script> <link rel="stylesheet" type="text/css" href="style.css"/> </head> <body> <header> <h1>Ping Pong</h1> </header> <footer> <script> </script> This is an example of creating a Ping Pong Game!<br><br> <div id="game"> <div id="playground"> <div id="paddleA" class="paddle"></div> <div id="paddleB" class="paddle"></div> <div id="ball"></div> </div> </div> </footer> </body> </html> |
Цитата:
И пример твой как запустить? Что это за Лего ты выложил? Что должно быть в итоге-то? :) |
Написал всё до этого момента и вот следующий 6 шаг - запустить )
6. Let's test what we just coded. Save all the files and open index.html in the web browser. 7. Try pressing the keys to control both paddles. The two paddles should move smoothly and respond at the same time without interruption. What just happened? We have used another approach to capture the keyboard input. Instead of doing the action once after the key press is detected, we store which keys are pressed and which are not. Afterwards, we use a JavaScript interval to check the pressed keys every 30 milliseconds. This approach enables us to know all the keys pressed at the time and so we can move both paddles at the same time. ![]() |
Ну так что ?
|
Цитата:
|
эх, как же так то везде сплошная коррупция ( :-?
|
Цитата:
|
Всё исправил (firebug ура)
|
Часовой пояс GMT +3, время: 21:55. |