home *** CD-ROM | disk | FTP | other *** search
/ com!online 2002 May / comcd0502.iso / homepage / special / javascript / 01_01 / Java / pinwheel2 / xMouse.js < prev   
Encoding:
JavaScript  |  2000-11-12  |  1.5 KB  |  58 lines

  1. /******************************************************************* 
  2. * File    : xMouse.js 
  3. * Created : 2000/07/15 
  4. * Author  : Roy Whittle  (Roy@Whittle.com) www.Roy.Whittle.com 
  5. * Purpose : To create a cross browser "Mouse" object.
  6. *        This library will allow scripts to query the current x,y
  7. *        coordinates of the browser
  8. * History 
  9. * Date         Version        Description 
  10. * 2000-06-08    1.0        Initial version
  11. * 2000-07-31    1.1        Some fixing up.
  12. * 2000-10-14    1.2        Now works in IE 5.0+
  13. ***********************************************************************/
  14. /*** Create an object able to hold the x,y coordinates ***/
  15. function xMouse() 
  16. {     this.X = 0;
  17.     this.Y = 0;
  18.  
  19.     if(navigator.appName.indexOf("Netscape") != -1)
  20.     {
  21.         this.getMouseXY = function (evnt) 
  22.         {
  23.             document.ml.X=evnt.pageX;
  24.             document.ml.Y=evnt.pageY;
  25.         }
  26.  
  27.         window.captureEvents(Event.MOUSEMOVE);
  28.         window.onmousemove = this.getMouseXY;
  29.  
  30.         document.ml = this;
  31.     }
  32.     else if(document.all)
  33.     {
  34.         if(navigator.appVersion.indexOf("MSIE 5.") != -1)
  35.             this.getMouseXY = function ()
  36.             {
  37.                 document.ml.X = event.x + document.body.scrollLeft;
  38.                 document.ml.Y = event.y + document.body.scrollTop;
  39.             }
  40.         else
  41.             this.getMouseXY = function ()
  42.             {
  43.                 document.ml.X = event.x;
  44.                 document.ml.Y = event.y;
  45.             }
  46.  
  47.         document.ml = this;
  48.         document.onmousemove = this.getMouseXY;
  49.     } 
  50.     return(this);
  51.  
  52. }
  53. /*** End  - xMouse a cross browser "Mouse" object by www.Roy.Whittle.com ***/