有人可以帮我吗,我正在尝试实现拖放,我需要在拖动后更新我可以的元素x和y,但是当我再次拖动权利后,它会松开鼠标的位置,请参见下面的代码
event.source.dropContainer = event.source.boundaryElementSelector;
const element = event.source.getRootElement();
const boundingClientRect = element.getBoundingClientRect();
console.log(boundingClientRect, 'element');
const parentPosition = this.getPosition(element);
console.log('x: ' + (boundingClientRect.x - parentPosition.left), 'y: ' + (boundingClientRect.y - parentPosition.top));
this.dragAndDrop.emit(
{
x: (boundingClientRect.x - parentPosition.left),
y: (boundingClientRect.y - parentPosition.top),
class: className,
index: i,
});
element.style.removeProperty('transform');
element.style.setProperty('transform', 'translate3d(0px, 0px, 0px)', 'important');
}
getPosition(el) {
let x = 0;
let y = 0;
while (el && !isNaN(el.offsetLeft) && !isNaN(el.offsetTop)) {
x += el.offsetLeft - el.scrollLeft;
y += el.offsetTop - el.scrollTop;
el = el.offsetParent;
}
return { top: y, left: x };
}