How to set the widget location using jquery

Source: Internet
Author: User

JS-only method:
Copy codeThe Code is as follows:
Document. getElementById ("child"). style. left = "800px ";
Document. getElementById ("child"). style. top = "200px ";*/

// Offset () obtains the browsing position of the current element.
Var offsettop = $ ("# unamespan"). offset (). top;
Var offsetleft = $ ("# unamespan"). offset (). left;
// Position () obtains the position of the current element based on the parent container.
Var positiontop = $ ("# unamespan"). position (). top;
Var positionleft = $ ("# unamespan"). position (). left;

// Set the position of panel2 Based on the coordinates of unamespan
$ ("# Panel2" 2.16.css ({position: "absolute", 'top': offsettop + 100, 'left': offsetleft + 50, 'z-Index ': 2 });

First, you must set the position attribute of the control.
The position attribute specifies the positioning type of the element. This attribute defines the positioning mechanism used to establish the element layout. Any element can be located, but an absolute or fixed element will generate a block-level box regardless of the element type. The relative positioning element is offset from its default position in the normal stream.
Attribute description:
1 absolute: generates absolute positioning elements, which are located relative to the first parent element other than static positioning. The positions of elements are specified by the "left", "top", "right", and "bottom" attributes.

2 fixed generates absolute positioning elements, which are located relative to the browser window. The positions of elements are specified by the "left", "top", "right", and "bottom" attributes.

3. relative generates relative positioning elements and locates them relative to their normal locations. Therefore, "left: 20" adds 20 pixels to the LEFT position of the element.

4 static default value. The element is not located and appears in the normal stream (ignore the top, bottom, left, right, or z-index declarations ).
5 inherit specifies that the value of the position attribute should be inherited from the parent element. (This attribute is not supported in ie)

The default value of position in all spaces is static, so you need to set it to other attributes for positioning.

If you need to set the hierarchy of layers for multiple layers, you need to set the z-index attribute.

The z-index attribute sets the stacking sequence of elements. Elements with a higher stacking order are always in front of elements with a lower stacking order.

Note: An element can have a negative z-index attribute value.

Note: Z-index can only work on the positioning element (the position value is not static )!

Description
This attribute sets the position of a positioning element along the z axis. The z axis is defined as the axis vertically extending to the display area. If it is a positive number, it is closer to the user. If it is a negative number, it indicates it is farther away from the user.

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.