Skip to content

Commit 36fa086

Browse files
mgoldmethvin
andcommitted
Offset: Send px-ed strings to .css()
An upcoming release of Migrate will generate warnings for calls to `.css()` that pass numbers rather than strings, see jquery/jquery-migrate#296. At the moment, core's `.offset()` setter passes numbers rather than px strings so it would throw warnings. This commit fixes that. Ref jquerygh-4508 Co-authored-by: Dave Methvin <dave.methvin@gmail.com>
1 parent 90fed4b commit 36fa086

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

src/offset.js

+6-3
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ jQuery.offset = {
1212
var curPosition, curLeft, curCSSTop, curTop, curOffset, curCSSLeft, calculatePosition,
1313
position = jQuery.css( elem, "position" ),
1414
curElem = jQuery( elem ),
15+
numberProps = {},
1516
props = {};
1617

1718
// Set position first, in-case top/left are set even on static elem
@@ -44,14 +45,16 @@ jQuery.offset = {
4445
}
4546

4647
if ( options.top != null ) {
47-
props.top = ( options.top - curOffset.top ) + curTop;
48+
numberProps.top = ( options.top - curOffset.top ) + curTop;
49+
props.top = numberProps.top + "px";
4850
}
4951
if ( options.left != null ) {
50-
props.left = ( options.left - curOffset.left ) + curLeft;
52+
numberProps.left = ( options.left - curOffset.left ) + curLeft;
53+
props.left = numberProps.left + "px";
5154
}
5255

5356
if ( "using" in options ) {
54-
options.using.call( elem, props );
57+
options.using.call( elem, numberProps );
5558

5659
} else {
5760
curElem.css( props );

0 commit comments

Comments
 (0)