你好,我的代码有问题当我单击左词"艾哈迈德"时,转到左侧 5 像素再次单击5像素时,问题是我需要在键盘单词移动中单击左侧并继续移动直到我让钥匙顺便说一下,想象网站中的数字 10 我想通过在继续单击时单击向下单击来增加 10该值将减小
输入这里,看看我的问题http://masry.host56.com/moving_object/index.php
你在这里,我一直在为你做这个小提琴:
<p id="move" style="position:absolute;left:0;top:0;">test</p>
.JS:
$(document).ready(function(){
var element = $( "#move" )
, doc = $( document )
, Motion
, goRight = function(){
element.css( "left" ,1+ parseInt(element.css( "left")));
if ( Motion === goRight ) {
setTimeout( goRight , 10 );
}
}
goUp = function(){
element.css( "top" , parseInt(element.css( "top")) -1);
if ( Motion === goUp ) {
setTimeout( goUp , 10 );
}
}
goDown = function(){
element.css( "top" ,1+ parseInt(element.css( "top")));
if ( Motion === goDown ) {
setTimeout( goDown , 10 );
}
}
goleft = function(){
element.css( "left" ,parseInt(element.css( "left"))-1);
if ( Motion === goleft ) {
setTimeout( goleft , 10 );
}
};
doc.keydown( function( e ) {
if ( e.which === 39 && Motion !== goRight ) {
Motion = goRight;
goRight();
}
else if( e.which === 38 && Motion !== goUp){
Motion = goUp;
goUp();
}
else if( e.which === 37 && Motion !== goleft){
Motion = goleft;
goleft();
}
else if( e.which ===40 && Motion !== goDown){
Motion = goDown;
goDown();
}
} );
doc.keyup( function () {
Motion = null;
} );
});
http://jsfiddle.net/Imadbakir/5yShL/22/