Skip to content

Offset: Be more precise about the origins for .offset() and .position() #1027

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 25, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Offset: Be more precise about the origins for .offset() and .position()
  • Loading branch information
gibson042 committed Mar 20, 2017
commit 5a64df4bed4414cf07dead40c045020a2718c191
6 changes: 3 additions & 3 deletions entries/offset.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
</signature>
<desc>Get the current coordinates of the first element in the set of matched elements, relative to the document.</desc>
<longdesc>
<p>The <code>.offset()</code> method allows us to retrieve the current position of an element <em>relative to the document</em>. Contrast this with <code><a href="/position/">.position()</a></code>, which retrieves the current position <em>relative to the offset parent</em>. When positioning a new element on top of an existing one for global manipulation (in particular, for implementing drag-and-drop), <code>.offset()</code> is more useful.</p>
<p>The <code>.offset()</code> method allows us to retrieve the current position of an element (specifically its border box, which excludes margins) <em>relative to the document</em>. Contrast this with <code><a href="/position/">.position()</a></code>, which retrieves the current position <em>relative to the offset parent</em>. When positioning a new element on top of an existing one for global manipulation (in particular, for implementing drag-and-drop), <code>.offset()</code> is more useful.</p>
<p><code>.offset()</code> returns an object containing the properties <code>top</code> and <code>left</code>.</p>
<div class="warning">
<p><strong>Note:</strong> jQuery does not support getting the offset coordinates of hidden elements or accounting for borders, margins, or padding set on the body element.</p>
<p><strong>Note:</strong> jQuery does not support getting the offset coordinates of hidden elements.</p>
<p>While it is possible to get the coordinates of elements with <code>visibility:hidden</code> set, <code>display:none</code> is excluded from the rendering tree and thus has a position that is undefined.</p>
</div>
</longdesc>
Expand Down Expand Up @@ -96,7 +96,7 @@ $( "*", document.body ).click(function( event ) {
</signature>
<desc>Set the current coordinates of every element in the set of matched elements, relative to the document.</desc>
<longdesc>
<p>The <code>.offset()</code> setter method allows us to reposition an element. The element's position is specified <em>relative to the document</em>. If the element's <code>position</code> style property is currently <code>static</code>, it will be set to <code>relative</code> to allow for this repositioning.</p>
<p>The <code>.offset()</code> setter method allows us to reposition an element. The element's border-box position is specified <em>relative to the document</em>. If the element's <code>position</code> style property is currently <code>static</code>, it will be set to <code>relative</code> to allow for this repositioning.</p>
</longdesc>
<example>
<desc>Set the offset of the second paragraph:</desc>
Expand Down
4 changes: 2 additions & 2 deletions entries/position.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
</signature>
<desc>Get the current coordinates of the first element in the set of matched elements, relative to the offset parent.</desc>
<longdesc>
<p>The <code>.position()</code> method allows us to retrieve the current position of an element <em>relative to the offset parent</em>. Contrast this with <code><a href="/offset/">.offset()</a></code>, which retrieves the current position <em>relative to the document</em>. When positioning a new element near another one and within the same containing DOM element, <code>.position()</code> is the more useful.</p>
<p>The <code>.position()</code> method allows us to retrieve the current position of an element (specifically its margin box) <em>relative to the offset parent</em> (specifically its padding box, which excludes margins and borders). Contrast this with <code><a href="/offset/">.offset()</a></code>, which retrieves the current position <em>relative to the document</em>. When positioning a new element near another one and within the same containing DOM element, <code>.position()</code> is the more useful.</p>
<p>Returns an object containing the properties <code>top</code> and <code>left</code>.</p>
<div class="warning">
<p><strong>Note:</strong> jQuery does not support getting the position coordinates of hidden elements or accounting for borders, margins, or padding set on the body element.</p>
<p><strong>Note:</strong> jQuery does not support getting the position coordinates of hidden elements.</p>
</div>
</longdesc>
<note id="dimensions-number" type="additional" data-title=".position()"/>
Expand Down