Javascript drag-and-drop series Article 3 details page 1/4 of event objects

Source: Internet
Author: User

Before reading this article, read offsetleft, offsettop, offsetwidth, and offsetheight attributes in the Javascript Drag and Drop Series article 2. Article To clarify the context.
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 meanings (refer Program Design) Well, 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

BelowCodeIs 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 >
< Meta HTTP-equiv = "Content-Type" Content = "Text/html; charsets = UTF-8" />
< Title > Untitled document </ Title >
< Style Type = "Text/CSS" >

Body {
Border : 1px solid black ;
Margin : 0px ;
}
</ Style >
< Script Type = "Text/JavaScript" Language = "JavaScript" >
Document. onmousemove = Move;
Function Move (e ){
If ( ! E)
{
E = Window. event;
}
VaR Xelement = Document. getelementbyid ( " X " );
VaR Yelement = Document. getelementbyid ( " Y " );
Xelement. Value = E. clientx;
Yelement. Value = E. clienty;

}
</ Script >
</ Head >
< Body >
< Input Type = "Text" ID = "X" Value = "" />
< Input Type = "Text" ID = "Y" Value = "" />
</ Body >
</ Html >

3 type attribute

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.