-1
我目前有一個對象,我可以使用鍵盤上的箭頭鍵移動,但是,該對象移出屏幕。我怎樣才能讓對象留在屏幕上?如何防止移動字符離開屏幕
$(document).ready(function(){
$(document).keydown(function(key) {
switch(parseInt(key.which,10)) {
case 37:
$('img').animate({left: "-=30px"}, 'fast');
break;
case 38:
$('img').animate({top: '-=30px'},'fast');
break;
case 39:
$('img').animate({left: '+=30px'},'fast');
break;
case 40:
$('img').animate({top: '+=30px'},'fast');
break;
}
});
});
你的代碼在哪裏? –
已添加代碼 – Pyro