I have a <div>
element with position: absolute
inside a container with position: relative
. Its left
and top
properties are bound to data X and Y in the component.ts
. My purpose is to move the div inside my container using cdk drag and drop.
On the dragEnded
event I retrive the data I need to update the coordinates X and Y and so begins the problem...
<div
class="character"
[style.left.px]="x"
[style.top.px]="y"
cdkDrag
cdkDragBoundary=".grid-container"
(cdkDragEnded)="dragEnded($event, c)"
></div>
I notice that cdk drag and drop apply a property transform: translate3d(x,y,z)
in order to move my div, starting from its original position. So, if I want my div left and top to be bound to my backend properties I can just calculate new coordinates on dragEnd event, apply them, and reset the transform property made by cdk. Everything works.
But the next time I drag the element, material don't apply the transform starting from the new absolute position of my div, but from the original one.
I thought one solution could be to check if the CdkDragEnd event
contains the data relative to the transform starting point and reset it, but I didn't find anything.
Any idea if this proprty is hidden somewhere in the CdkDragEvent? Or have any other solution to this problem?