Pure JS writing method:
//offset() gets the position of the current element based on browsing
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; #unamespan").position().left;
//Set the position of panel2 based on the coordinates of unamespan
$("#panel2").css({position: "absolute",'top' :offsettop 100,'left':offsetleft 50,'z-index':2});
3 relative generates a relatively positioned element, positioned relative to its normal position. Therefore, "left:20" adds 20 pixels to the element's LEFT position.
4 static default value. Without positioning, the element appears in normal flow (ignoring 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)
If there are multiple layers and you need to set the hierarchical relationship of the layers, you need to set the z-index attribute
The z-index attribute sets the stacking order of elements. Elements with a higher stacking order will always appear in front of elements with a lower stacking order.
Note: Elements can have negative z-index attribute values.
Note: Z-index only works on positioned elements (the value of position is not static)!
Description
This attribute sets the position of a positioned element along the z-axis, which is defined as the axis extending vertically to the display area. If it is a positive number, it is closer to the user, and if it is a negative number, it is further away from the user.