Skip to content

Commit 9bf9b1f

Browse files
mattlunnkswedberg
authored andcommitted
Dimensions methods: Note that various height/width methods may return inaccurate value if parent is hidden. Fixes jquery#469. Closes jquery#544.
1 parent bb5a21d commit 9bf9b1f

File tree

7 files changed

+16
-7
lines changed

7 files changed

+16
-7
lines changed

entries/height.xml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ $( document ).height();
2525
<p><strong>Note:</strong> Although <code>style</code> and <code>script</code> tags will report a value for <code>.width()</code> or <code>height()</code> when absolutely positioned and given <code>display:block</code>, it is strongly discouraged to call those methods on these tags. In addition to being a bad practice, the results may also prove unreliable.</p>
2626
</div>
2727
</longdesc>
28-
<note id="dimensions-number" type="additional" data-title=".height()"/>
28+
<note id="dimensions-number" type="additional" data-title=".height()"/>
29+
<note id="inaccurate-dimensions-for-hidden-elements" type="additional" data-title=".height()"/>
2930
<example>
3031
<desc>Show various heights. Note the values are from the iframe so might be smaller than you expected. The yellow highlight shows the iframe body.</desc>
3132
<code><![CDATA[
@@ -92,7 +93,7 @@ $( "#getw" ).click(function() {
9293
<argument name="height" type="Integer" />
9394
<return>
9495
<type name="String"/>
95-
<type name="Number"/>
96+
<type name="Number"/>
9697
</return>
9798
<desc>A function returning the height to set. Receives the index position of the element in the set and the old height as arguments. Within the function, <code>this</code> refers to the current element in the set.</desc>
9899
</argument>

entries/innerHeight.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
</p>
1717
</longdesc>
1818
<note id="dimensions-number" type="additional" data-title=".innerHeight()"/>
19+
<note id="inaccurate-dimensions-for-hidden-elements" type="additional" data-title=".innerHeight()"/>
1920
<example>
2021
<desc>Get the innerHeight of a paragraph.</desc>
2122
<code><![CDATA[

entries/innerWidth.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
</p>
1616
</longdesc>
1717
<note id="dimensions-number" type="additional" data-title=".innerWidth()"/>
18+
<note id="inaccurate-dimensions-for-hidden-elements" type="additional" data-title=".innerWidth()"/>
1819
<example>
1920
<desc>Get the innerWidth of a paragraph.</desc>
2021
<code><![CDATA[

entries/outerHeight.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
</p>
1717
</longdesc>
1818
<note id="dimensions-number" type="additional" data-title=".outerHeight()"/>
19+
<note id="inaccurate-dimensions-for-hidden-elements" type="additional" data-title=".outerHeight()"/>
1920
<example>
2021
<desc>Get the outerHeight of a paragraph.</desc>
2122
<code><![CDATA[

entries/outerWidth.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
</p>
1818
</longdesc>
1919
<note id="dimensions-number" type="additional" data-title=".outerWidth()"/>
20+
<note id="inaccurate-dimensions-for-hidden-elements" type="additional" data-title=".outerWidth()"/>
2021
<example>
2122
<desc>Get the outerWidth of a paragraph.</desc>
2223
<code><![CDATA[

entries/width.xml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ $( document ).width();
2525
<p><strong>Note:</strong> Although <code>style</code> and <code>script</code> tags will report a value for <code>.width()</code> or <code>height()</code> when absolutely positioned and given <code>display:block</code>, it is strongly discouraged to call those methods on these tags. In addition to being a bad practice, the results may also prove unreliable.</p>
2626
</div>
2727
</longdesc>
28-
<note id="dimensions-number" type="additional" data-title=".width()"/>
28+
<note id="dimensions-number" type="additional" data-title=".width()"/>
29+
<note id="inaccurate-dimensions-for-hidden-elements" type="additional" data-title=".width()"/>
2930
<example>
3031
<desc>Show various widths. Note the values are from the iframe so might be smaller than you expected. The yellow highlight shows the iframe body.</desc>
3132
<code><![CDATA[
@@ -88,11 +89,11 @@ $("#getw").click(function() {
8889
<added>1.4.1</added>
8990
<argument name="function" type="Function">
9091
<argument name="index" type="Integer" />
91-
<argument name="value" type="Integer" />
92+
<argument name="value" type="Integer" />
9293
<return>
9394
<type name="String"/>
94-
<type name="Number"/>
95-
</return>
95+
<type name="Number"/>
96+
</return>
9697
<desc>A function returning the width to set. Receives the index position of the element in the set and the old width as arguments. Within the function, <code>this</code> refers to the current element in the set.</desc>
9798
</argument>
9899
</signature>

notes.xsl

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<code>undefined</code> is not recognised as a data value. Calls such as <code><xsl:value-of select="@data-title" />( <xsl:value-of select="@data-parameters" />, undefined )</code> will return the corresponding data for "name", and is therefore the same as <code><xsl:value-of select="@data-title" />( <xsl:value-of select="@data-parameters" /> )</code>.
66
</xsl:when>
77
<xsl:when test="@id = 'dimensions-number'">
8-
The numbers returned by dimensions-related APIs, including <code><xsl:value-of select="@data-title"/></code>, may be fractional in some cases. Code should not assume it is an integer. Also, dimensions may be incorrect when the page is zoomed by the user; browsers do not expose an API to detect this condition.
8+
The number returned by dimensions-related APIs, including <code><xsl:value-of select="@data-title"/></code>, may be fractional in some cases. Code should not assume it is an integer. Also, dimensions may be incorrect when the page is zoomed by the user; browsers do not expose an API to detect this condition.
99
</xsl:when>
1010
<xsl:when test="@id = 'disconnected-manipulation'">
1111
Prior to jQuery 1.9, <code><xsl:value-of select="@data-title"/></code> would attempt to add or change nodes in the current jQuery set if the first node in the set was not connected to a document, and in those cases return a new jQuery set rather than the original set. The method might or might not have returned a new result depending on the number or connectedness of its arguments! As of jQuery 1.9, <code>.after()</code>, <code>.before()</code>, and <code>.replaceWith()</code> always return the original unmodified set. Attempting to use these methods on a node without a parent has no effect—that is, neither the set nor the nodes it contains are changed.
@@ -16,6 +16,9 @@
1616
<xsl:when test="@id = 'domlint'">
1717
Forms and their child elements should not use input names or ids that conflict with properties of a form, such as <code>submit</code>, <code>length</code>, or <code>method</code>. Name conflicts can cause confusing failures. For a complete list of rules and to check your markup for these problems, see <a href="http://kangax.github.com/domlint/">DOMLint</a>.
1818
</xsl:when>
19+
<xsl:when test="@id = 'inaccurate-dimensions-for-hidden-elements'">
20+
The value reported by <code><xsl:value-of select="@data-title" /></code> is not guaranteed to be accurate when the element's parent is hidden. To get an accurate value, you should show the parent first, before using <code><xsl:value-of select="@data-title" /></code>.
21+
</xsl:when>
1922
<xsl:when test="@id = 'jquery-selector-extension'">
2023
Because <code><xsl:value-of select="@data-selector"/></code> is a jQuery extension and not part of the CSS specification, queries using <code><xsl:value-of select="@data-selector"/></code> cannot take advantage of the performance boost provided by the native DOM <code>querySelectorAll()</code> method. To achieve the best performance when using <code><xsl:value-of select="@data-selector"/></code> to select elements, first select the elements using a pure CSS selector, then use <a href="/filter/"><code>.filter("<xsl:value-of select="@data-selector"/>")</code></a>.
2124
</xsl:when>

0 commit comments

Comments
 (0)