Layout Options

  • Fixed Header
    Makes the header top fixed, always visible!
  • Fixed Sidebar
    Makes the sidebar left fixed, always visible!
Introduction
Webconcept

Description

The .offset() method sets or returns the offset (position) for the selected elements, relative to the document.


Return Offset Coordinates

Returns the offset coordinates of the FIRST matched element.

This method returns an object with 2 properties, top and left, which represent the top and left positions in pixels

v1.2

This method has the form:

.offset()

Return Value

This form returns an Object.


Set Offset Coordinates

Sets the offset coordinates of ALL matched elements

v1.4

This method has the alternate form:

.offset(value)
Parameter Description
value (required) Specifies the top and left coordinates in pixels.

Possible values:
  • Value pair, like {top:100,left:0}
  • An object with top and left properties

Return Value

This form returns a jQuery object.


Set Offset Coordinates Using a Function

Using a function to set the offset coordinates of ALL matched elements

v1.4

This method has the alternate form:

.offset(function(index,oldoffset))
Parameter Description
function(index, oldoffset) Specifies a function that returns an object containing the top and left coordinates.
  • index - (optional) Receives the index position of the selector
  • oldoffset - (optional) Receives the current coordinates of the selector

Return Value

This form returns a jQuery object.

Examples

Get the current offset position of a p element:

$("button").click(function(){
  x=$("p").offset();
  alert("Left offset: " + x.left + " Top offset: " + x.top);
});