AngularMaterial拖放在CSS转换结束后调用回调的问题
创始人
2024-10-28 11:01:31
0

可以使用animationEnd事件来检测CSS过渡的结束,然后在回调函数中执行相关操作。以下是示例代码:

HTML:


  Drag me!

TS:

import { Component, OnInit, ViewChild, ElementRef } from '@angular/core';
import { CdkDragEnd } from '@angular/cdk/drag-drop';

@Component({
  selector: 'app-drag-example',
  templateUrl: './drag-example.component.html',
  styleUrls: ['./drag-example.component.scss']
})
export class DragExampleComponent implements OnInit {

  @ViewChild('dragItem') dragItem: ElementRef;

  ngOnInit() {
    const item = this.dragItem.nativeElement;
    if (!item) {
      return;
    }

    item.addEventListener('animationend', (e: AnimationEvent) => {
      if (e.animationName === 'cdk-drag-placeholder') {
        // Place your code here, the animation is finished
      }
    });
  }

  onDragEnded(event: CdkDragEnd) {
    const item = event.source.element.nativeElement;

    // Reset the animation
    item.classList.add('cdk-drag-placeholder');
    item.style.transform = 'translate3d(0, 0, 0)';
    item.addEventListener('animationend', (e: AnimationEvent) => {
      if (e.animationName === 'cdk-drag-placeholder') {
        // Place your code here, the animation is finished
      }
    });
  }
}

请注意,在HTML中我们使用了“cdkDragReleased”代替默认事件,以在释放拖动项时调用“onDragEnded”函数。在函数中,我们需要重置动画并添加“animationend”事件侦听器来检测过渡的结束。同样,在ngOnInit中,我们检测元素上的“animationend”事件以处理完成动画时的操作。

相关内容

热门资讯

一分钟辅助!约局吧作弊脚本,h... 一分钟辅助!约局吧作弊脚本,hhpkoer辅助器,秘籍教程(真的有挂)1、让任何用户在无需约局吧作弊...
第五分钟辅助!德州透视插件,w... 第五分钟辅助!德州透视插件,wepoker私人局外卦,经验教程(有挂方法)1、下载好wepoker私...
九分钟辅助!aapoker辅助... 九分钟辅助!aapoker辅助软件合法吗,拱趴大菠萝挂哪里,指引教程(有挂头条)1、全新机制【aap...
六分钟辅助!wepoker免费... 六分钟辅助!wepoker免费透视脚本,wepoker安装教程,指南书教程(有挂分析)1、wepok...
3分钟辅助!wepoker私局... 3分钟辅助!wepoker私局代打,xpoker透视辅助,指南教程(有挂透明挂)1、wepoker私...
第九分钟辅助!pokemmo脚... 第九分钟辅助!pokemmo脚本辅助下载,wepoker透视器免费,资料教程(有挂教程)进入游戏-大...
第1分钟辅助!wpk透视辅助靠... 您好,wpk透视辅助靠谱吗这款游戏可以开挂的,确实是有挂的,需要了解加去威信【136704302】很...
4分钟辅助!werplan透视... 4分钟辅助!werplan透视挂,pokernow辅助工具,策略教程(有挂详细)1、pokernow...
6分钟辅助!aapoker真的... 6分钟辅助!aapoker真的假的,wepoker开脚本视频,技法教程(有挂解惑)1、下载好wepo...
第一分钟辅助!we poker... 第一分钟辅助!we poker免费辅助器,wpk插件,绝活儿教程(有挂分享)1、we poker免费...