Skip to content

Commit 3de7d8b

Browse files
committed
Position: Check for fraction support.
1 parent f76873c commit 3de7d8b

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed

ui/jquery.ui.position.js

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,12 @@ $.fn.position = function( options ) {
183183
position.left += myOffset[ 0 ];
184184
position.top += myOffset[ 1 ];
185185

186+
// if the browser doesn't support fractions, then round for consistent results
187+
if ( !$.support.offsetFractions ) {
188+
position.left = Math.round( position.left );
189+
position.top = Math.round( position.top );
190+
}
191+
186192
collisionPosition = {
187193
marginLeft: marginLeft,
188194
marginTop: marginTop
@@ -406,6 +412,45 @@ $.ui.position = {
406412
}
407413
};
408414

415+
// fraction support test
416+
(function () {
417+
var testElement, testElementParent, testElementStyle, offsetLeft, i
418+
body = document.getElementsByTagName( "body" )[ 0 ],
419+
div = document.createElement( "div" );
420+
421+
//Create a "fake body" for testing based on method used in jQuery.support
422+
testElement = document.createElement( body ? "div" : "body" );
423+
testElementStyle = {
424+
visibility: "hidden",
425+
width: 0,
426+
height: 0,
427+
border: 0,
428+
margin: 0,
429+
background: "none"
430+
};
431+
if ( body ) {
432+
jQuery.extend( testElementStyle, {
433+
position: "absolute",
434+
left: "-1000px",
435+
top: "-1000px"
436+
});
437+
}
438+
for ( i in testElementStyle ) {
439+
testElement.style[ i ] = testElementStyle[ i ];
440+
}
441+
testElement.appendChild( div );
442+
testElementParent = body || document.documentElement;
443+
testElementParent.insertBefore( testElement, testElementParent.firstChild );
444+
445+
div.style.cssText = "position: absolute; left: 10.7432222px;";
446+
447+
offsetLeft = $( div ).offset().left;
448+
$.support.offsetFractions = offsetLeft > 10 && offsetLeft < 11;
449+
450+
testElement.innerHTML = "";
451+
testElementParent.removeChild( testElement );
452+
})();
453+
409454
// DEPRECATED
410455
if ( $.uiBackCompat !== false ) {
411456
// offset option

0 commit comments

Comments
 (0)