Js event objects offsetX, pageX, screenX, clientX Detailed let Firefox support offsetX, offsetY

   Usually difficult to determine the position of the measurement element, various properties are given below in the specific event object for future use.
 
  Detecting the position relative to the browser: clientX and clientY
    When a mouse event occurs, the mouse position relative to the upper left corner of the browser
    
  Detection with respect to the location of the document: pageX and pageY
    When a mouse event occurs, the mouse position relative to the upper left corner of the document. (IE7 / 8 None) (and similar event.clientX event.clientY)
 
       Detecting the position relative to the screen: screenX and screenY
    When a mouse event occurs, the mouse position relative to the upper left corner of the screen
 
       Detecting the position relative to the source of the event: offsetX and offsetY
    When a mouse event occurs, the mouse position relative to the upper left corner of the element incident
 

Different browser compatible event event:

 
 
 

tip:  make Firefox support offsetX, offsetY

 
// For the cursor coordinates relative to the parent element of a positioning 
function Coordinate (E) { 
  var the window.event || E = O, 
      coord, 
      coord_X, 
      coord_Y; 

  coord_X = (o.offsetX === undefined) getOffset? (O) .X: o.offsetX; 
  coord_Y = (o.offsetY === undefined) getOffset (O) .Y: o.offsetY;? 
  coord = { "coord_X": coord_X, "coord_Y": coord_Y}; 
  return coord; 
} 
function getOffset (E) { 
  var target = e.target, // trigger current audience 
      eventCoord, 
      pageCoord, 
      offsetCoord; 

  // calculate the current distance from the document to the trigger elements 
  pageCoord = getPageCoord (target); 

  // calculate the cursor distance to documentation 
  eventCoord = { 
    X-: window.pageXOffset + e.clientX,
    The Y: window.pageYOffset + e.clientY
  }; 

  // subtract the parent element to obtain the first cursor positioning coordinates 
  offsetCoord {= 
    X-: eventCoord.X - pageCoord.X, 
    the Y: eventCoord.Y - pageCoord.Y 
  }; 
  return offsetCoord; 
}

  

 


 

The future will continue to add content  

Guess you like

Origin www.cnblogs.com/bigharbour/p/11419670.html