On the offset () method of jquery and its example sharing _jquery

Source: Internet
Author: User

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:

<! DOCTYPE html>
 
 

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:

<! DOCTYPE html>
 
 

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:

<! DOCTYPE html>
 
 

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.

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.