JavaScript 监听键盘方向键


document.onkeydown = function(ev){
var ev = ev || window.event;
switch(ev.keyCode){
case 37:
cc.log('左');
case 100:
//cc.log('1');
//oH3.style.left = oH3.offsetLeft - 10 + "px";
break;
case 38:
cc.log('上');
case 104:
//cc.log('6');
//oH3.style.top = oH3.offsetTop - 10 + "px";
break;
case 39:
cc.log('右');
case 102:
//cc.log('45');
//oH3.style.left = oH3.offsetLeft + 10 + "px";
break;
case 40:
cc.log('下');
case 98:
//cc.log('3');
//oH3.style.top = oH3.offsetTop + 10 + "px";
break;
default:
console.log("请按上下左右键");
break;
}
//console.log(oH3.offsetTop+"+"+oH3.style.top);
console.log(ev.keyCode);

}


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM