jQuery offset() Method
jQuery offset() Method
The offset() method is used to set or return the offset coordinates for the selected elements, relative to the document.
For your Information:-
When it is used to return the offset coordinates of the FIRST matched element. It will return an object with 2 properties i.e, the top and left positions in pixels.
When it is used to sets the offset coordinates, it will set for ALL matched elements.
Syntax:-
- Its syntax for returning offset coordinates is:- $(selector).offset()
- Its syntax for setting offset coordinates is:- $(selector).offset({top:value,left:value})
- Its syntax for setting coordinates with function is:- $(selector).offset(function(index,currentoffset))
Further Explanation:-
Parameter | Description |
---|---|
{top:value,left:value} | Required when setting the offset. Specifies the top and left coordinates in pixels. |
function(index,currentoffset) | Optional. Specifies a function that returns an object containing the top and left coordinates
|