Definition and usage of the offset () method:
This method returns or sets the offset of the matched element relative to the document object.
grammatical structure One :
$ (selector). Offset ()
Gets the relative offset of the matching element in the current document.
The returned object contains two integer genera: Top and left.
This method is valid only for visible elements.
Instance code:
The above code can eject the child div's offset relative to the document.
syntax structure two :
$ (selector). Offset (value)
Sets the coordinates of the matching element relative to the document object.
The offset () method allows us to reset the position of the element. The position of this element is relative to the document object.
If the object's original position style property is static, it is changed to relative to achieve relocation.
Parameter list:
Parameter description
Value provides the top and left coordinates in pixels.
Possible values:
1. Value pairs, such as {top:200,left:10}.
2. Objects with top and left properties.
Instance code:
The above code can set the offset of the div relative to the document.
grammatical structure three :
Use the return value of the function to set the offset coordinates:
$ (selector). Offset (function (Index,oldoffset))
Parameter list:
Parameter description
function (Index,oldvalue) provides functions that return the new offset coordinates of the selected element:
Index-Optional. The index of the element.
OldValue-Optional. The current coordinates.
Instance code:
The above code can also set the offset of the element, but the value is returned through the function.
The above mentioned is the entire content of this article, I hope you can enjoy.