Skip to content
Fetching contributors…
Cannot retrieve contributors at this time
106 lines (102 sloc) 5.66 KB
<?xml version="1.0"?>
<entry name="position" type="method" return="jQuery">
<desc>Position an element relative to another.</desc>
<p>The jQuery UI <code>.position()</code> method allows you to position an element relative to the window, document, another element, or the cursor/mouse, without worrying about offset parents.</p>
<p><em>Note: jQuery UI does not support positioning hidden elements.</em></p>
<p>This is a standalone jQuery plugin and has no dependencies on other jQuery UI components.</p>
<xi:include href="../includes/core-extension-desc.xml" xmlns:xi=""/>
<argument name="options" type="Object">
<property name="my" default='"center"'>
<desc>Defines which position <strong>on the element being positioned</strong> to align with the target element: "horizontal vertical" alignment. A single value such as <code>"right"</code> will be normalized to <code>"right center"</code>, <code>"top"</code> will be normalized to <code>"center top"</code> (following CSS convention). Acceptable horizontal values: <code>"left"</code>, <code>"center"</code>, <code>"right"</code>. Acceptable vertical values: <code>"top"</code>, <code>"center"</code>, <code>"bottom"</code>. Example: <code>"left top"</code> or <code>"center center"</code>. Each dimension can also contain offsets, in pixels or percent, e.g., <code>"right+10 top-25%"</code>. Perecentage offsets are relative to the element being positioned.</desc>
<type name="String"/>
<property name="at" default='"center"'>
<desc>Defines which position <strong>on the target element</strong> to align the positioned element against: "horizontal vertical" alignment. See the <a href="#option-my"><code>my</code></a> option for full details on possible values. Perecentage offsets are relative to the target element.</desc>
<type name="String"/>
<property name="of" default="null">
<desc>Which element to position against. If you provide a selector or jQuery object, the first matching element will be used. If you provide an event object, the <code>pageX</code> and <code>pageY</code> properties will be used. Example: <code>"#top-menu"</code></desc>
<type name="Selector"/>
<type name="Element"/>
<type name="jQuery"/>
<type name="Event"/>
<property name="collision" default='"flip"'>
<p>When the positioned element overflows the window in some direction, move it to an alternative position. Similar to <a href="#option-my"><code>my</code></a> and <a href="#option-at"><code>at</code></a>, this accepts a single value or a pair for horizontal/vertical, e.g., <code>"flip"</code>, <code>"fit"</code>, <code>"fit flip"</code>, <code>"fit none"</code>.</p>
<li><code>"flip"</code>: Flips the element to the opposite side of the target and the collision detection is run again to see if it will fit. Whichever side allows more of the element to be visible will be used.</li>
<li><code>"fit"</code>: Shift the element away from the edge of the window.</li>
<li><code>"flipfit"</code>: First applies the flip logic, placing the element on whichever side allows more of the element to be visible. Then the fit logic is applied to ensure as much of the element is visible as possible.</li>
<li><code>"none"</code>: Does not apply any collision detection.</li>
<type name="String"/>
<property name="using" default="null">
When specified, the actual property setting is delegated to this callback. Receives two parameters: The first is a hash of <code>top</code> and <code>left</code> values for the position that should be set and can be forwarded to <code>.position()</code> or <code>.animate()</code>.
<p>The second provides feedback about the position and dimensions of both elements, as well as calculations to their relative position. Both <code>target</code> and <code>element</code> have these properties: <code>element</code>, <code>left</code>, <code>top</code>, <code>width</code>, <code>height</code>. In addition, there's <code>horizontal</code>, <code>vertical</code> and <code>important</code>, giving you twelve potential directions like <code>{ horizontal: "center", vertical: "left", important: "horizontal" }</code>.</p>
<type name="Function"/>
<property name="within" default="window">
<desc>Element to position within, affecting collision detection. If you provide a selector or jQuery object, the first matching element will be used.</desc>
<type name="Selector"/>
<type name="Element"/>
<type name="jQuery"/>
<desc>A simple jQuery UI Position example.</desc>
.positionDiv {
position: absolute;
width: 75px;
height: 75px;
background: green;
$( "#position1" ).position({
my: "center",
at: "center",
of: "#targetElement"
$( "#position2" ).position({
my: "left top",
at: "left top",
of: "#targetElement"
$( "#position3" ).position({
my: "right center",
at: "right bottom",
of: "#targetElement"
$( document ).mousemove(function( event ) {
$( "#position4" ).position({
my: "left+3 bottom-3",
of: event,
collision: "fit"
<div id="targetElement">
<div class="positionDiv" id="position1"></div>
<div class="positionDiv" id="position2"></div>
<div class="positionDiv" id="position3"></div>
<div class="positionDiv" id="position4"></div>
<category slug="methods"/>
<category slug="overrides"/>
<category slug="utilities"/>
Jump to Line
Something went wrong with that request. Please try again.