Before reading this article, you can read offsetLeft, offsetTop, offsetWidth, and offsetHeight attributes in the Javascript Drag and Drop Series Article 2 to clarify the context relationship.
Okay. Let's get started.
Attributes/methods with the same model
1 Button Property
Integer type, readable and writable. For a specific mouse event, it indicates the mouse button that is pressed. It can be dragged to determine whether the mousedown event is triggered by the left mouse button. All its values and their meanings (refer to "Javascript advanced programming") are good. Let's get started.
3.1 properties/methods of the window. Event object
3.1.1 The IE event model and DOM events are as follows:
0-button not pressed
1-Left click
2-right-click
3-press both the left and right buttons
4-Press the middle key
5-Press the left and middle buttons
6-Right-click and right-click
7. Right-click both the left and right buttons.
The value returned by the button attribute of mouseup is exactly the same as that in the mousedown event.
Note: In all browsers compatible with the DOM event model, 0 indicates that the left button is pressed, the value 1 does not exist, and 2 indicates that the right button is pressed. For non-mouse events, "undefined" is returned ".
2. clientX and clientY attributes
The two attributes are of Integer type, in pixels, and readable and writable type. The x and y coordinates of the mouse in the client area of the browser (excluding the toolbar and scroll bar) When related events occur. It would be better to use an image to explain it. Please refer:
Figure 3.1: clientX and clientY attributes
The following code is a very simple example. It can locate the coordinates of the mouse at any time and display the results in two text boxes. If you want to, you can try to run it, compatible with all modern browsers.
Sample Code 1:
<!Doctype html public "-// W3C // dtd html 4.01 // EN" "http://www.w3.org/TR/html4/strict.dtd">
<Html>
<Head>
<MetaHttp-equiv= "Content-Type"Content= "Text/html; charsets = UTF-8" />
<Title>Untitled Document</Title>
<StyleType= "Text/css">
Body{
Border:1px solid black;
Margin:0px;
}
</Style>
<ScriptType= "Text/javascript"Language= "JavaScript">
Document. onmousemove=Move;
FunctionMove (e ){
If(!E)
{
E=Window. event;
}
VarXElement=Document. getElementById ("X");
VarYElement=Document. getElementById ("Y");
XElement. value=E. clientX;
YElement. value=E. clientY;
}
</Script>
</Head>
<Body>
<InputType= "Text"Id= "X"Value= "" />
<InputType= "Text"Id= "Y"Value= "" />
</Body>
</Html>
3 type attribute