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

Source: Internet
Author: User
The event object in Javascript is similar to the derived class inherited from EventArgs class in. NET. It is used to pass status information to the event handler for corresponding operations. This article describes several attributes related to the implementation of the drag-and-drop function in the Javascript event object, and finally encapsulates the differences between the IE event model and the standard DOM event model into a class, to adapt to all browsers. 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:

. 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:

 



Untitled Documenttitle>
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.