Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 202
  • Last Modified:

document.onmousemove

Hi,
  I am building a web page in which I need to know the specific coordinates of the mouse at all times.
I have plugged in a script I have found, which seems to capture the coordinates ok. THe problem is that
there is sometimes a delay, and other times I move the mouse, the browser simply does not respond to it.
I have implemented document.onmousemove, and assigned to a function. Is there a way to improve overall
response time, and remove any delay of the detected movement?
0
RockyFullen
Asked:
RockyFullen
  • 2
1 Solution
 
gops1Commented:
Use attachEvent or EventListener or combination of both to capture the mouse events and then capture the coordinates.
You have to use both only if you need to bring browser compatibility.
0
 
gops1Commented:
Try this code:

<html>
      <head>
            <title>Mouse</title>
            <script language="JavaScript1.2">
                  var IE = document.all?true:false;
                  if (!IE) document.captureEvents(Event.MOUSEDOWN)
                  document.onmousedown = getMouseXY;
                  var tempX = 0;
                  var tempY = 0;
                  function getMouseXY(e) {
                        if (IE) { // grab the x-y pos.s if browser is IE
                              tempX = event.clientX + document.body.scrollLeft;
                              tempY = event.clientY + document.body.scrollTop;
                        }else {  // grab the x-y pos.s if browser is NS
                              tempX = e.pageX;
                              tempY = e.pageY;
                        }  
                        if (tempX < 0){tempX = 0;}
                        if (tempY < 0){tempY = 0;}  
                        document.Show.MouseX.value = tempX;
                        document.Show.MouseY.value = tempY;
                        return true;
                  }
            </script>
      </head>
<BODY>

<form name="Show">
X <input type="text" name="MouseX" value="0" size="4"><br>
Y <input type="text" name="MouseY" value="0" size="4"><br>
</form>

</body>
</html>

Hope this is what you wanted
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now