解决方法
你应该遵循keydown和keyup并使用间隔来更顺畅地移动球拍.
演示:http://jsfiddle.net/M7TKc/16/
var paddle = $("#paddle"); paddle.css({backgroundColor: "red",height:"100px",width:"25px",position: "absolute"}); var paddle_y = 0,moving = 0; /* added */ draw_paddle(); window.setInterval(function () { /* added */ if (moving != 0) { paddle_y += moving; draw_paddle(); }},100); function move_down(){ moving = -10; } function move_up(){ moving = 10; } function draw_paddle(){ paddle.css({top: paddle_y+"px"}); } $(document).keypress(function(e) { if(e.which == 13) { // stop on "ENTER" moving = 0; } }); $(document).keydown(function(e){ /* changed */ if (e.keyCode == 38) move_down(); else if (e.keyCode == 40) move_up(); }); $(document).keyup(function(e){ /* added */ if (e.keyCode == 38 || e.keyCode == 40) moving = 0; });