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