Skip to content

Commit 17cc040

Browse files
committed
fix(anchorScroll): find offset of nested elements correctly
Closes #618
1 parent 9bc928f commit 17cc040

File tree

3 files changed

+13
-49
lines changed

3 files changed

+13
-49
lines changed

js/utils/dom.js

+3-9
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,10 @@
1717
* until we are at the direct child of parentEl
1818
* use-case: find scroll offset of any element within a scroll container
1919
*/
20-
getPositionInParent: function(el, parentEl) {
21-
var left = 0, top = 0;
22-
while (el && el !== parentEl) {
23-
left += el.offsetLeft;
24-
top += el.offsetTop;
25-
el = el.parentNode;
26-
}
20+
getPositionInParent: function(el) {
2721
return {
28-
left: left,
29-
top: top
22+
left: el.offsetLeft,
23+
top: el.offsetTop
3024
};
3125
},
3226

test/js/utils/dom.js

-40
This file was deleted.

test/js/utils/dom.unit.js

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
2+
describe('js/utils/dom', function() {
3+
4+
describe('getPositionInParent', function() {
5+
it('should return el.{offsetLeft,offsetTop}', function() {
6+
var el = { offsetLeft: 3, offsetTop: 4 };
7+
expect(ionic.DomUtil.getPositionInParent(el)).toEqual({ left: 3, top: 4 });
8+
});
9+
});
10+
});

0 commit comments

Comments
 (0)