I want to set the placeholder height to height of dragging element.
For now I'm using static height placeholder of smallest possible element height. I couldn't find any informations about how to do it and for now having no idea.
component html
<div class="taskList" cdkDropList id="{{ 'cdk-task-drop-list-' + categoryId }}" [cdkDropListData]="taskList"
[cdkDropListConnectedTo]="categoryIdList" (cdkDropListDropped)="onDrop($event)">
<ng-container *ngIf="task.isApproved || task.authorId===userId || userAccessLevel >= 3">
<div class="placeholder" *cdkDragPlaceholder></div>
<div class="task">
...
</div>
</ng-container>
</div>
css
.placeholder{
position: relative;
margin-top: 1px;
margin-bottom: 5px;
min-height: 75px;
transition: transform 250ms cubic-bezier(0, 0, 0.2, 1);
vertical-align: middle;
}
Any ideas?
Try to get height of dragging element, and based on this, change placeholder height.
cdkDragStarted(event:any){
this.height = event.source.element.nativeElement.offsetHeight
}
HTML:
<div class="example-box" *ngFor="let movie of movies; let i = index" (cdkDragStarted)="cdkDragStarted($event)" cdkDrag >
<div [ngStyle]="{'min-height.px':height }" class="example-custom-placeholder" *cdkDragPlaceholder></div>
{{movie}}
</div>
Here is my example: https://stackblitz.com/edit/angular-zhdujp-kppghs?file=src/app/cdk-drag-drop-custom-placeholder-example.ts
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With