我有这个 fiddle :http://jsfiddle.net/ps4t9/4/
$(window).keydown(function (e) {
if (e.which == 38) { player.animate({ top: '-=20px' }); shuriken.animate({ top: '-=20px' }); } // up
if (e.which == 40) { player.animate({ top: '+=20px' }); shuriken.animate({ top: '+=20px' }); } // down
if (e.which == 32) { shuriken.animate({ left: '+=280px' });} // space bar hit
});
如何防止玩家移动到容器边界之外?
最佳答案
您可以使用 if 语句
if (e.which == 32){
if(shuriken.css('left') != '249px'){
shuriken.animate({ 'left' : '+=280px' });
}
}
关于javascript - 当图像到达容器边界时停止移动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17759800/