Skip to content

Commit 0e31d5a

Browse files
dmethvinkswedberg
authored andcommitted
Dimensions: values are non-integer and unreliable zoomed. Fixes gh-76, gh-103
1 parent a7a562c commit 0e31d5a

File tree

9 files changed

+21
-10
lines changed

9 files changed

+21
-10
lines changed

entries/height.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?xml version="1.0"?>
22
<entries>
33
<desc>Get the current computed height for the first element in the set of matched elements or set the height of every matched element.</desc>
4-
<entry type="method" name="height" return="Integer">
4+
<entry type="method" name="height" return="Number">
55
<title>.height()</title>
66
<signature>
77
<added>1.0</added>
@@ -22,6 +22,7 @@ $( document ).height(); // returns height of HTML document
2222
<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>
2323
</div>
2424
</longdesc>
25+
<note id="dimensions-number" type="additional" data-title=".height()"/>
2526
<example>
2627
<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>
2728
<code><![CDATA[

entries/innerHeight.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version="1.0"?>
2-
<entry type="method" name="innerHeight" return="Integer">
2+
<entry type="method" name="innerHeight" return="Number">
33
<title>.innerHeight()</title>
44
<signature>
55
<added>1.2.6</added>
@@ -12,6 +12,7 @@
1212
<img src="/resources/0042_04_02.png"/>
1313
</p>
1414
</longdesc>
15+
<note id="dimensions-number" type="additional" data-title=".innerHeight()"/>
1516
<example>
1617
<desc>Get the innerHeight of a paragraph.</desc>
1718
<code><![CDATA[

entries/innerWidth.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version="1.0"?>
2-
<entry type="method" name="innerWidth" return="Integer">
2+
<entry type="method" name="innerWidth" return="Number">
33
<title>.innerWidth()</title>
44
<signature>
55
<added>1.2.6</added>
@@ -12,6 +12,7 @@
1212
<img src="/resources/0042_04_05.png"/>
1313
</p>
1414
</longdesc>
15+
<note id="dimensions-number" type="additional" data-title=".innerWidth()"/>
1516
<example>
1617
<desc>Get the innerWidth of a paragraph.</desc>
1718
<code><![CDATA[

entries/offset.xml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515
<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>
1616
</div>
1717
</longdesc>
18-
<example>
18+
<note id="dimensions-number" type="additional" data-title=".offset()"/>
19+
<example>
1920
<desc>Access the offset of the second paragraph:</desc>
2021
<code><![CDATA[
2122
var p = $( "p:last" );
@@ -81,7 +82,7 @@ $( "*", document.body ).click(function( event ) {
8182
<signature>
8283
<added>1.4</added>
8384
<argument name="coordinates" type="PlainObject">
84-
<desc>An object containing the properties <code>top</code> and <code>left</code>, which are integers indicating the new top and left coordinates for the elements.</desc>
85+
<desc>An object containing the properties <code>top</code> and <code>left</code>, which are numbers indicating the new top and left coordinates for the elements.</desc>
8586
</argument>
8687
</signature>
8788
<signature>

entries/outerHeight.xml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,21 @@
11
<?xml version="1.0"?>
2-
<entry type="method" name="outerHeight" return="Integer">
2+
<entry type="method" name="outerHeight" return="Number">
33
<title>.outerHeight()</title>
44
<signature>
55
<added>1.2.6</added>
66
<argument name="includeMargin" optional="true" type="Boolean">
77
<desc>A Boolean indicating whether to include the element's margin in the calculation.</desc>
88
</argument>
99
</signature>
10-
<desc>Get the current computed height for the first element in the set of matched elements, including padding, border, and optionally margin. Returns an integer (without "px") representation of the value or null if called on an empty set of elements.</desc>
10+
<desc>Get the current computed height for the first element in the set of matched elements, including padding, border, and optionally margin. Returns a number (without "px") representation of the value or null if called on an empty set of elements.</desc>
1111
<longdesc>
1212
<p>The top and bottom padding and border are always included in the <code>.outerHeight()</code> calculation; if the <code>includeMargin</code> argument is set to <code>true</code>, the margin (top and bottom) is also included.</p>
1313
<p>This method is not applicable to <code>window</code> and <code>document</code> objects; for these, use <code><a href="/height/">.height()</a></code> instead.</p>
1414
<p class="image">
1515
<img src="/resources/0042_04_03.png"/>
1616
</p>
1717
</longdesc>
18+
<note id="dimensions-number" type="additional" data-title=".outerHeight()"/>
1819
<example>
1920
<desc>Get the outerHeight of a paragraph.</desc>
2021
<code><![CDATA[

entries/outerWidth.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version="1.0"?>
2-
<entry type="method" name="outerWidth" return="Integer">
2+
<entry type="method" name="outerWidth" return="Number">
33
<title>.outerWidth()</title>
44
<signature>
55
<added>1.2.6</added>
@@ -16,6 +16,7 @@
1616
<img src="/resources/0042_04_06.png"/>
1717
</p>
1818
</longdesc>
19+
<note id="dimensions-number" type="additional" data-title=".outerWidth()"/>
1920
<example>
2021
<desc>Get the outerWidth of a paragraph.</desc>
2122
<code><![CDATA[

entries/position.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212
<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>
1313
</div>
1414
</longdesc>
15-
<example>
15+
<note id="dimensions-number" type="additional" data-title=".position()"/>
16+
<example>
1617
<desc>Access the position of the second paragraph:</desc>
1718
<code><![CDATA[
1819
var p = $( "p:first" );

entries/width.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?xml version="1.0"?>
22
<entries>
33
<desc>Get the current computed width for the first element in the set of matched elements or set the width of every matched element.</desc>
4-
<entry type="method" name="width" return="Integer">
4+
<entry type="method" name="width" return="Number">
55
<title>.width()</title>
66
<signature>
77
<added>1.0</added>
@@ -22,6 +22,7 @@ $( document ).width();
2222
</code></pre>
2323
<p>Note that <code>.width()</code> will always return the content width, regardless of the value of the CSS <code>box-sizing</code> property. As of jQuery 1.8, this may require retrieving the CSS width plus <code>box-sizing</code> property and then subtracting any potential border and padding on each element when the element has <code>box-sizing: border-box</code>. To avoid this penalty, use <code>.css( "width" )</code> rather than <code>.width()</code>.</p>
2424
</longdesc>
25+
<note id="dimensions-number" type="additional" data-title=".width()"/>
2526
<example>
2627
<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>
2728
<code><![CDATA[

notes.xsl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
22
<xsl:template name="note">
33
<xsl:choose>
4+
<xsl:when test="@id = 'dimensions-number'">
5+
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.
6+
</xsl:when>
47
<xsl:when test="@id = 'document-order'">
58
Selected elements are in the order of their appearance in the document.
69
</xsl:when>

0 commit comments

Comments
 (0)