标签:c style class blog code java
判断两个图片接近的时候用了绝对值的算法
1 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> 2 <html> 3 <head> 4 <title> 004 </title> 5 <script type="text/javascript" language="javascript"> 6 7 8 function move(obj) 9 { 10 var wugui_height=59; 11 var wugui_width=61; 12 var cock_height=40; 13 var cock_width=39; 14 var wugui=document.getElementByIdx_x("wugui"); 15 if(window.event) 16 { 17 key=obj.keyCode; 18 } 19 20 var wugui_top=wugui.style.top; 21 var wugui_left=wugui.style.left; 22 23 24 wugui_top=parseInt(wugui_top.substring(0,wugui_top.indexOf("p"))); 25 wugui_left=parseInt(wugui_left.substring(0,wugui_left.indexOf("p"))); 26 27 28 if(obj.value=="down"||key==83) 29 {wugui_top=wugui_top+10; 30 wugui.style.top=(wugui_top+10)+"px"; 31 } 32 else if(obj.value=="up"||key==87) 33 {wugui_top=wugui_top-10; 34 wugui.style.top=(wugui_top-10)+"px"; 35 } 36 else if(obj.value=="left"||key==65) 37 {wugui_left=wugui_left-10; 38 wugui.style.left=(wugui_left-10)+"px"; 39 } 40 else if(obj.value=="right"||key==68) 41 {wugui_left=wugui_left+10; 42 wugui.style.left=(wugui_left+10)+"px"; 43 } 44 var cock=document.getElementByIdx_x("cock"); 45 46 var cock_top=cock.style.top; 47 var cock_left=cock.style.left; 48 49 cock_top=parseInt(cock_top.substring(0,cock_top.indexOf("p"))); 50 cock_left=parseInt(cock_left.substring(0,cock_left.indexOf("p"))); 51 52 x=Math.abs(cock_top-wugui_top); 53 y=Math.abs(cock_left-wugui_left); 54 55 if(x<60&&y<59) 56 { 57 alert("hahah"); 58 wugui.style.top=220+"px"; 59 wugui.style.left=220+"px"; 60 61 } 62 63 } 64 65 function test() 66 { 67 var t=document.getElementByIdx_x("td"); 68 69 } 70 71 72 73 </script> 74 </head> 75 113 </body> 114 </html>
标签:c style class blog code java
原文地址:http://www.cnblogs.com/sweetculiji/p/3778924.html