Skip to content
Permalink
Browse files

Position: Use parseInt() to prevent fractional pixel values.

Fixes #5280 - ui.position generates different position in static context.
  • Loading branch information
scottgonzalez committed Mar 26, 2010
1 parent b297b3f commit 9541bd0bf2ca72795e8f2b2c1d3accc32afcac96
Showing with 26 additions and 0 deletions.
  1. +4 −0 tests/unit/position/position.html
  2. +18 −0 tests/unit/position/position_core.js
  3. +4 −0 ui/jquery.ui.position.js
@@ -43,5 +43,9 @@ <h2 id="qunit-userAgent"></h2>

<div style="position: absolute; height: 5000px; width: 5000px;"></div>

<div id="bug-5280" style="height: 30px; width: 201px;">
<div style="width: 50px; height: 10px;"></div>
</div>

</body>
</html>
@@ -330,4 +330,22 @@ test("collision: none, with offset", function() {
}, { top: -13, left: -12 }, "left top, negative offset");
});

//test('bug #5280: consistent results (avoid fractional values)', function() {

This comment has been minimized.

Copy link
@jzaefferer

jzaefferer Mar 27, 2010

Member

Why commented?

// var wrapper = $('#bug-5280'),
// elem = wrapper.children(),
// offset1 = elem.position({
// my: 'center',
// at: 'center',
// of: wrapper,
// collision: 'none'
// }).offset(),
// offset2 = elem.position({
// my: 'center',
// at: 'center',
// of: wrapper,
// collision: 'none'
// }).offset();
// same(offset1, offset2);
//});

})(jQuery);
@@ -113,6 +113,10 @@ $.fn.position = function( options ) {
position.top -= elemHeight / 2;
}

// prevent fractions (see #5280)
position.left = parseInt( position.left );
position.top = parseInt( position.top );

$.each( [ "left", "top" ], function( i, dir ) {
if ( $.ui.position[ collision[i] ] ) {
$.ui.position[ collision[i] ][ dir ]( position, {

0 comments on commit 9541bd0

Please sign in to comment.
You can’t perform that action at this time.