Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

104 lines (100 sloc) 5.738 kb
<?xml version="1.0"?>
<entry name="position" type="method" return="jQuery">
<title>.position()</title>
<desc>Position an element relative to another.</desc>
<longdesc>
<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="http://www.w3.org/2003/XInclude"/>
</longdesc>
<added>1.8</added>
<signature>
<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>
<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>
<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>
<property name="collision" default='"flip"'>
<desc>
<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>
<ul>
<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>
</ul>
</desc>
<type name="String"/>
</property>
<property name="using" default="null">
<desc>
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>
</desc>
<type name="Function"/>
</property>
<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"/>
</property>
</argument>
</signature>
<example>
<desc>A simple jQuery UI Position example.</desc>
<css><![CDATA[
.positionDiv {
position: absolute;
width: 75px;
height: 75px;
background: green;
}
]]></css>
<code><![CDATA[
$( "#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"
});
});
]]></code>
<html><![CDATA[
<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>
</div>
]]></html>
</example>
<category slug="utilities"/>
</entry>
Jump to Line
Something went wrong with that request. Please try again.