Skip to content

Commit afdf0ad

Browse files
committed
fix(listView): position dragged list item properly when list view's parent is offset. Closes #1583
1 parent 40392c0 commit afdf0ad

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

Diff for: js/views/listView.js

+11-3
Original file line numberDiff line numberDiff line change
@@ -186,16 +186,24 @@
186186
this.el = opts.el;
187187
this.scrollEl = opts.scrollEl;
188188
this.scrollView = opts.scrollView;
189+
// Get the True Top of the list el http://www.quirksmode.org/js/findpos.html
190+
this.listEl.trueTop = 0;
191+
if (this.listEl.offsetParent) {
192+
var obj = this.listEl;
193+
do {
194+
this.listEl.trueTop += obj.offsetTop;
195+
obj = obj.offsetParent;
196+
} while (obj);
197+
}
189198
};
190199

191200
ReorderDrag.prototype = new DragOp();
192201

193202
ReorderDrag.prototype._moveElement = function(e) {
194203
var y = e.gesture.center.pageY +
195204
this.scrollView.getValues().top -
196-
this.scrollView.__container.offsetTop -
197205
(this._currentDrag.elementHeight / 2) -
198-
this.listEl.offsetTop;
206+
this.listEl.trueTop;
199207
this.el.style[ionic.CSS.TRANSFORM] = 'translate3d(0, '+y+'px, 0)';
200208
};
201209

@@ -231,7 +239,7 @@
231239

232240
var scrollY = 0;
233241
var pageY = e.gesture.center.pageY;
234-
var offset = this.listEl.offsetTop + this.scrollView.__container.offsetTop;
242+
var offset = this.listEl.trueTop;
235243

236244
//If we have a scrollView, check scroll boundaries for dragged element and scroll if necessary
237245
if (this.scrollView) {

0 commit comments

Comments
 (0)