Query - Position API reference for Query methods related to element positioning and intersection crosshair API Reference
Categories

Query - Position

Get element positions and check spatial relationships between elements.

Position

position

$('selector').position()
$('selector').position(options)

Gets or sets element position coordinates with flexible reference systems.

Parameters

NameTypeDescription
relativeTostring/Element/QueryElement to measure relative to
topnumberTop position to set
leftnumberLeft position to set
precision'pixel' | 'subpixel'Rounding precision. Default: 'pixel'
type'global' | 'local' | 'relative'Coordinate system to return

Returns

Position object with { top, left } coordinates. Default returns all coordinate systems: { global, local, relative? }.

Example

pagePosition

$('selector').pagePosition()
$('selector').pagePosition({ precision: 'subpixel' })

Gets element position relative to the document (viewport position + scroll offset).

Parameters

NameTypeDescription
precision'pixel' | 'subpixel'Rounding precision. Default: 'pixel'

Returns

Position object with { top, left } coordinates relative to document.

Example

Intersection

intersects

$('selector').intersects(target)
$('selector').intersects(target, options)

Checks if elements intersect with a target.

Note Uses outerWidth and outerHeight (includes padding and border) for intersection calculations.

Parameters

NameTypeDescription
targetstring/Element/QueryTarget element(s)
optionsobjectOptions
Options
NameTypeDefaultDescription
sidesstring/array'all'Sides to check: 'top', 'bottom', 'left', 'right'
thresholdnumber0Minimum intersection ratio (0-1)
fullybooleanfalseSource must be fully contained
returnDetailsbooleanfalseReturn detailed intersection data
allbooleanfalseAll elements must intersect (vs any)

Returns

Boolean, or details object when returnDetails: true.

Example

Previous
Logical Operators
Next
Collections