jquery method to set the position of a control _jquery

Source: Internet
Author: User

Pure JS Writing:

Copy Code code as follows:

document.getElementById ("Child"). style.left= "800px";
document.getElementById ("Child"). style.top= "200px";

Offset () Gets the location of the current element based on the browse
var offsettop=$ ("#unamespan"). Offset (). Top;
var offsetleft=$ ("#unamespan"). Offset (). Left;
Position () Gets the location of the current element based on the parent container
var positiontop=$ ("#unamespan"). Position (). Top;
var positionleft=$ ("#unamespan"). Position (). Left;

Set the position of the Panel2 based on Unamespan coordinates
$ ("#panel2"). CSS ({position: "absolute", ' top ': offsettop+100, ' left ': offsetleft+50, ' Z-index ': 2});


You first need to set the control's Position property
The Position property defines the positioning type of the element, which define the positioning mechanism used to establish the element layout. Any element can be positioned, but an absolute or fixed element generates a block-level box regardless of the type of element itself. The relative positioning element is offset from its default position in the normal stream.
Attribute Description:
1 Absolute: Generates an absolutely positioned element that is positioned relative to the first parent element other than static positioning. The position of the element is defined by the "left", "Top", "right" and "bottom" properties.

2 fixed generates an absolutely positioned element that is positioned relative to the browser window. The position of the element is defined by the "left", "Top", "right" and "bottom" properties.

3 relative to generate the relative positioning of the element, relative to its normal position to locate. Therefore, "left:20" adds 20 pixels to the left position of the element.

4 static default value. Without positioning, the elements appear in the normal stream (ignoring top, bottom, left,right, or z-index declarations).
5 inherit specify that the value of the position attribute should be inherited from the parent element. (this attribute is not supported in IE)

The default value for all space position is static, so you need to set it to another property to navigate

You need to set the Z-index property if you have multiple layers that require a hierarchical relationship of layers

The Z-index property sets the stacking order of the elements. Elements that have a higher stacking order are always in front of elements that have a lower stacking order.

Note: The element can have a negative Z-index property value.

Note: Z-index can only work on positioned elements (position values are not static)!

Description
This property sets the position of an anchor element along the z-axis, which is defined as the axis that extends vertically to the display area. A positive number is closer to the user and a negative number means 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.