Tracking the mouse using x, y coordinates can be useful to move web page items (images) and to determine the location of the mouse. Consider these three examples.
  1. Window events can be captured using the object: window.event
    document.onmousemove = mouseMove;
    function mouseMove(e)
    {
       var MovedX, MovedY;
      
       if (window.event)
         e= window.event;
      MovedX=e.clientX ;
      MovedY=e.clientY ;
    

    Image follows mouse
  2. The Mouse up and Mouse Down events can also be captured. When the mouse down event occurs and the user moves the mouse, the image can follow the mouse. When mouse down occurs, the drag is ended.
    var xLoc, yLoc, drg=false;
    document.onmousemove = mouseMove;
    document.onmouseup = mouseUp;
    function mouseDown(e)
    {
      if (window.event)
         e=window.event
      xLoc=e.clientX - document.getElementById("tee").offsetLeft;
      yLoc=e.clientY - document.getElementById("tee").offsetTop;
      drg=true;
    }
    function mouseUp(e)
    {
       drg=false;
    }
    function mouseMove()
    {
       var MovedX, MovedY;
       if (!drg)
         return;
       if (window.event)
         e= window.event;
      MovedX=e.clientX - xLoc;
      MovedY=e.clientY - yLoc;
      
      document.getElementById("tee").style.left=MovedX;
      document.getElementById("tee").style.top=MovedY;
      
      return false;
    }
    Dragging Images in IE (not Firefox)
  3. By using the visibility property, multiple images can be manipulated to simulate "following". Mouse Trails