From afdf0ad764e29a2f8f0301e0d4e81f50afa2e16b Mon Sep 17 00:00:00 2001 From: Perry Govier Date: Fri, 6 Jun 2014 15:14:52 -0500 Subject: [PATCH] fix(listView): position dragged list item properly when list view's parent is offset. Closes #1583 --- js/views/listView.js | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/js/views/listView.js b/js/views/listView.js index 1136baab0f7..48f5534baa8 100644 --- a/js/views/listView.js +++ b/js/views/listView.js @@ -186,6 +186,15 @@ this.el = opts.el; this.scrollEl = opts.scrollEl; this.scrollView = opts.scrollView; + // Get the True Top of the list el http://www.quirksmode.org/js/findpos.html + this.listEl.trueTop = 0; + if (this.listEl.offsetParent) { + var obj = this.listEl; + do { + this.listEl.trueTop += obj.offsetTop; + obj = obj.offsetParent; + } while (obj); + } }; ReorderDrag.prototype = new DragOp(); @@ -193,9 +202,8 @@ ReorderDrag.prototype._moveElement = function(e) { var y = e.gesture.center.pageY + this.scrollView.getValues().top - - this.scrollView.__container.offsetTop - (this._currentDrag.elementHeight / 2) - - this.listEl.offsetTop; + this.listEl.trueTop; this.el.style[ionic.CSS.TRANSFORM] = 'translate3d(0, '+y+'px, 0)'; }; @@ -231,7 +239,7 @@ var scrollY = 0; var pageY = e.gesture.center.pageY; - var offset = this.listEl.offsetTop + this.scrollView.__container.offsetTop; + var offset = this.listEl.trueTop; //If we have a scrollView, check scroll boundaries for dragged element and scroll if necessary if (this.scrollView) {