Skip to content

Commit d1d1c64

Browse files
committed
Handle positioning correctly when inside a positioned parent
and that parent may not be the containment element
1 parent f09c970 commit d1d1c64

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

src/angular-sortable-view.js

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -420,6 +420,7 @@
420420

421421
var target = $element;
422422
var clientRect = $element[0].getBoundingClientRect();
423+
var parentRect = getPositionedParentRect($element[0]);
423424
var clone;
424425

425426
if(!helper) helper = $controllers[0].helper;
@@ -459,8 +460,10 @@
459460
if(targetLeft + helperRect.width > containmentRect.left + body.scrollLeft + containmentRect.width) // right boundary
460461
targetLeft = containmentRect.left + body.scrollLeft + containmentRect.width - helperRect.width;
461462

462-
targetLeft -= containmentRect.left;
463-
targetTop -= containmentRect.top;
463+
if (parentRect) {
464+
targetLeft -= parentRect.left;
465+
targetTop -= parentRect.top;
466+
}
464467
}
465468
this.style.left = targetLeft - body.scrollLeft + 'px';
466469
this.style.top = targetTop - body.scrollTop + 'px';
@@ -499,6 +502,16 @@
499502
}, clone, $element, placeholder, $controllers[0].getPart(), $scope.$index);
500503
}
501504
}
505+
506+
function getPositionedParentRect(el) {
507+
while (el !== document.documentElement) {
508+
el = el.parentNode;
509+
var cssPos = el.style.position;
510+
if (cssPos != '' && cssPos != 'static') {
511+
return el.getBoundingClientRect();
512+
}
513+
}
514+
}
502515
}
503516
};
504517
}]);

0 commit comments

Comments
 (0)