]> source.dussan.org Git - jquery.git/commitdiff
Use parseFloat instead of parseInt to read CSS values. 182/head
authorSylvester Keil <sylvester@keil.or.at>
Sat, 15 Jan 2011 12:56:20 +0000 (13:56 +0100)
committerSylvester Keil <sylvester@keil.or.at>
Sat, 15 Jan 2011 12:56:20 +0000 (13:56 +0100)
This fixes #7730 and #7885.

src/offset.js
test/unit/offset.js

index 2040c9d83ac9d5db4f15159cc980fbab5c2506fd..94b67c77a99f11789263d4edf3bcd702d52576bd 100644 (file)
@@ -187,11 +187,13 @@ jQuery.offset = {
                // need to be able to calculate position if either top or left is auto and position is absolute
                if ( calculatePosition ) {
                        curPosition = curElem.position();
+                       curTop = curPosition.top;
+                       curLeft = curPosition.left;
+               } else {
+                       curTop = parseFloat( curCSSTop ) || 0;
+                       curLeft = parseFloat( curCSSLeft ) || 0;
                }
 
-               curTop  = calculatePosition ? curPosition.top  : parseInt( curCSSTop,  10 ) || 0;
-               curLeft = calculatePosition ? curPosition.left : parseInt( curCSSLeft, 10 ) || 0;
-
                if ( jQuery.isFunction( options ) ) {
                        options = options.call( elem, i, curOffset );
                }
index cfa14449b7359ccaf53a55abd36926c6e04b2dc6..1f8c3b15c9d0650b6e5bc7177dde1b5ac382cd7b 100644 (file)
@@ -422,6 +422,32 @@ test("offsetParent", function(){
        equals( div[1], jQuery("#nothiddendiv")[0], "The div is the offsetParent." );
 });
 
+test("fractions (see #7730 and #7885)", function() {
+       expect(2);
+       
+       jQuery('body').append('<div id="fractions"/>');
+       
+       var expected = { top: 1000, left: 1000 };
+       var div = jQuery('#fractions');
+       
+       div.css({
+               position: 'absolute',
+               left: '1000.7432222px',
+               top: '1000.532325px',
+               width: 100,
+               height: 100
+       });
+       
+       div.offset(expected);
+       
+       var result = div.offset();
+
+       equals( result.top, expected.top, "Check top" );
+       equals( result.left, expected.left, "Check left" );
+       
+       div.remove();
+});
+
 function testoffset(name, fn) {
 
        test(name, function() {