Document directory
- Location
- Alignment
- Implementation
Introduction
Many controls need to be located and displayed on the specific location of the page, or on other DOM alignment locations (up, down, and down). This is a feature of the control, is A typical Has-A relationship, so we will actually have two extensions available:
- Position: controls location-related extensions
- Align: extension of control alignment with other elements
Location
The position of a widget on a page is the position of the widget relative to the page coordinate (0, 0). We use (x, y) to mark:
Here, offset is used to indicate the relative position of the DOM node on the page. $ (). offset () in jQuery can be obtained. The algorithm for calculating the offset is not described here.
- X coordinate of the offset. left Control
- Y coordinate of the offset. top Control
The calculation and setting of the widget's location are relatively simple. The required properties and methods are also simple:
Attributes (including setter and getter) include:
- X: x coordinate of the control
- Y: y coordinate of the control
- Xy: the xy coordinate of the control.
Method:
- MoveTo: Move to a certain point
Alignment
Alignment is a location-based extension. First, let's take a look at some location points of the control:
- Tl: control top, left
- Tc: the top and middle of the control.
- Tr: control top, right
- Cl: center of the control, left
- Cc: the middle and middle of the control.
- Cr: middle of the control, right side
- Bl: Bottom of the control, left
- Bc: the bottom and middle of the control.
- Br: Bottom of the control, right
So when we define an alignment, for example, the alignment between element a and Element B (left, top) can be identified by [tl, tl:
We can use a combination of the nine vertices to achieve various alignment.
When alignment is used, we also need to specify the offset of the position as follows:
At this time, we can find that the attributes need to be specified for definition alignment:
- Node: aligned node
- Points: Alignment mode, such as [tl, tl]
- Offset: the offset, for example, [10, 10].
Provided methods:
Align (node, points, offset): align
Center (node): center, that is, the alignment of [cc, cc]
Implementation
Position implementation
Align implementation
Dialog example
There are many examples of alignment, such as date selection, display menu, editor and table editing.