Istvan

egér koordináta

Aug 26th, 2012
34
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 1.16 KB | None | 0 0
  1. <html>
  2. <head>
  3. <script type="text/javascript">
  4.  
  5. function getMouseXY(e) {
  6.   if (IE) { // grab the x-y pos.s if browser is IE
  7.     tempX = event.clientX + document.body.scrollLeft;
  8.     tempY = event.clientY + document.body.scrollTop;
  9.   }
  10.   else {  // grab the x-y pos.s if browser is NS
  11.     tempX = e.pageX;
  12.     tempY = e.pageY;
  13.   }  
  14.   if (tempX < 0){tempX = 0;}
  15.  if (tempY < 0){tempY = 0;}  
  16.  document.getElementById("output").innerHTML += tempX + " " + tempY + " </br>";
  17.   return true;
  18. }
  19.  
  20. function onmd() {
  21.   document.onmousemove = getMouseXY;
  22. }
  23. function onmu() {
  24.   document.onmousemove = null;
  25. }
  26.  
  27. function divClear(){
  28.   document.getElementById("output").innerHTML = "";
  29.   document.onmousemove = null;
  30. }
  31.  
  32. var IE = document.all?true:false;
  33. if (!IE) document.captureEvents(Event.MOUSEMOVE)
  34. var tempX = 0;
  35. var tempY = 0;
  36.  
  37. //document.onmousedown = onmd;
  38. //document.onmouseup = onmu;
  39.  
  40. </script>
  41.  
  42. </head>
  43.  
  44. <body>
  45. <div id="zold" onmousedown="onmd();" onmouseup="onmu();" style="width: 400px; height: 200px; background-color:green;">
  46.  
  47. </div>
  48. <INPUT TYPE=BUTTON OnClick="divClear();" VALUE="Clear">
  49. <div id="output">
  50.  
  51. </div>
  52. </body>
  53. </html>
Advertisement
Add Comment
Please, Sign In to add comment