键盘元素的控制小方块的移动效果
键盘元素的控制
ns4 = (document.layers)?true:false;
ie4 = (document.all)?true:false;
function init(){
if(ns4){block = document.blockDiv;}
if(ie4){block = blockDiv.style;}
block.xpos = parseInt(block.left);
block.active = false;
document.onkeydown = keyDown;
document.onkeyup = keyUp;
if(ns4){document.captureEvents(Event.KEYDOWN | Event.KEYUP);}
}
function keyDown(e){
if(ns4){var nkey=e.which;var iekey=0;}
if(ie4){var iekey=event.keyCode;var nkey=0;}
if((nkey==97 || iekey==65) && !block.active){
block.active = true;
slide();}
}
function keyUp(e){
if(ns4){var nkey=e.which;var iekey=0;}
if(ie4){var iekey=event.keyCode;var nkey=0;}
if(nkey==97 || iekey==65){
block.active = false;
}
}
function slide(){
if(block.active){
block.xpos += 5;
block.left = block.xpos;
status = block.xpos;
setTimeout("slide()",30);
}
}
//Javascript Document
请按"A"键,使方块滑动
~v~
[Ctrl+A 全选 注:如需引入外部Js需刷新才能执行]