<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>调速</title>
<script language="javascript">
ns4=(document.layers)?true:false;
ie4=(document.all)?true:false;
document.onkeydown=keydown
document.onkeyup=keyup
var direct;
var ekey;
var directkey;
function init(){
if(ns4) block=document.blockDiv;
if(ie4)block=blockDiv.style;
block.xpos=parseInt(block.left);
block.ypos=parseInt(block.top);
//alert(block.left);
block.active=0;
block.speed=5;
block.angle=0;
block.xinc=0;
block.yinc=0;
}
function keydown(){
ekey=event.keyCode;
if(block.active==1)
{
if(directkey<=40){
switch(directkey){
case 37:
switch(ekey){
case 38:
directkey=41;
break;
case 40:
directkey=44;
break;
}
break;
case 38:
switch(ekey){
case 39:
directkey=42;
break;
case 37:
directkey=41;
break;
}
break;
case 39:
switch(ekey){
case 38:
directkey=42;
break;
case 40:
directkey=43;
break;
}
break;
case 40:
switch(ekey){
case 39:
directkey=43;
break;
case 37:
directkey=44;
break;
}
break;
}
//alert("ttt");
}
}
else{
if((ekey==37)||(ekey==38)||(ekey==39)||(ekey==40)){
block.active=1;
block.getfocus;
directkey=ekey
}
}
switch(directkey){
case 37:
slide(37);
break;
case 38:
slide(38);
break;
case 39:
slide(39);
break;
case 40:
slide(40);
break;
case 41:
slide(41);
break;
case 42:
slide(42);
break;
case 43:
slide(43);
break;
case 44:
slide(44);
break;
}
}
function keyup(){
if(block.active==1){
block.active=0;
}
}
function slide(direct){
// alert("ttt");
if(block.active==1){
if(direct==37){
//alert("ttt");
block.xpos=block.xpos-block.speed;
block.left=block.xpos;
}
if(direct==38){
if(parseInt(block.top)>0){
block.ypos=block.ypos-block.speed;
block.top=block.ypos;
}
}
if(direct==39){
block.xpos=block.xpos+block.speed;
block.left=block.xpos;
}
if(direct==40){
block.ypos=block.ypos+block.speed;
block.top=block.ypos;
}
if(direct==41){
block.ypos=block.ypos-block.speed;
block.xpos=block.xpos-block.speed;
block.left=block.xpos;
block.top=block.ypos;
}
if(direct==42){
block.ypos=block.ypos-block.speed;
block.xpos=block.xpos+block.speed;
block.left=block.xpos;
block.top=block.ypos;
}
if(direct==43){
block.ypos=block.ypos+block.speed;
block.xpos=block.xpos+block.speed;
block.left=block.xpos;
block.top=block.ypos;
}
if(direct==44){
block.ypos=block.ypos+block.speed;
block.xpos=block.xpos-block.speed;
block.left=block.xpos;
block.top=block.ypos;
}
setTimeout("slide(direct)",30)
}
}
function speed(){
var speedvalue;
speedvalue=document.getElementById("speed");
switch(speedvalue.value){
case "slow":
block.speed=5;
break;
case "normal":
block.speed=10;
break;
case "quick":
block.speed=15;
break;
}
}
</script>
</head>
<body onload="init()">
<div id="blockDiv" style="position:absolute; left:400; top:200; width:30; visibility:visible;">
<table bgcolor="ff00ff" width=90 height=100>
<tr><td></td>
</tr>
</table>
</div>
<select id="speed">
<option value="slow">slow</option>
<option value="normal">normal</option>
<option value="quick">quick</option>
</select>
<a href="javascript:speed()">调速</a>
</body>
</html>
本文地址:http://com.8s8s.com/it/it30951.htm