Skip to content

Commit b1830c0

Browse files
Merge pull request #2437 from rrelmy/master
fix #2434 - wrong calculation of offset
2 parents 12c2867 + 0e47760 commit b1830c0

File tree

2 files changed

+29
-2
lines changed

2 files changed

+29
-2
lines changed

Source/Element/Element.Dimensions.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,8 +136,8 @@ Element.implement({
136136
isFixed = (styleString(this, 'position') == 'fixed');
137137

138138
return {
139-
x: bound.left.toInt() + elemScrolls.x + ((isFixed) ? 0 : htmlScroll.x) - html.clientLeft,
140-
y: bound.top.toInt() + elemScrolls.y + ((isFixed) ? 0 : htmlScroll.y) - html.clientTop
139+
x: bound.left.toFloat() + elemScrolls.x + ((isFixed) ? 0 : htmlScroll.x) - html.clientLeft,
140+
y: bound.top.toFloat() + elemScrolls.y + ((isFixed) ? 0 : htmlScroll.y) - html.clientTop
141141
};
142142
}
143143

Specs/Element/Element.Dimensions.js

100644100755
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,33 @@ describe('Element.Dimensions', function(){
193193
expect(relDiv.getPosition(div)).toEqual({x: 8, y: 8});
194194
});
195195

196+
it('should match subpixels if needed', function(){
197+
var oddSizedDiv = new Element('div', {
198+
styles: {
199+
width: 51,
200+
height: 51,
201+
margin: 5,
202+
visibility: 'hidden',
203+
position: 'relative',
204+
overflow: 'hidden',
205+
'float': 'left'
206+
}
207+
}).inject($(document.body));
208+
209+
var insideOddSizedDiv = new Element('div', {
210+
styles: {
211+
width: 10,
212+
height: 10,
213+
margin: 5.5,
214+
visibility: 'hidden',
215+
overflow: 'hidden'
216+
}
217+
}).inject(oddSizedDiv);
218+
219+
expect(insideOddSizedDiv.getPosition(oddSizedDiv).x)
220+
.toEqual(insideOddSizedDiv.getBoundingClientRect().left - oddSizedDiv.getBoundingClientRect().left);
221+
});
222+
196223
});
197224

198225
describe('Element.getCoordinates', function(){

0 commit comments

Comments
 (0)