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”事件以处理完成动画时的操作。

相关内容

热门资讯

wepoke有挂!wepoke... wepoke有挂!wepoke辅助挂,wepoke游戏真的是有挂的,教你教程(有挂解说)是由北京得w...
德扑ai智能!德州之星辅助器哪... 德扑ai智能!德州之星辅助器哪里买,德州之星切实是有挂(详细助手教程)1、超多福利:超高返利,海量正...
wpk透视辅助测试!wpk德州... wpk透视辅助测试!wpk德州专用辅助器(wPk)都是真的有挂-详细透视辅助教程;1、用户打开应用后...
德州免费辅助神器app!德州软... 德州免费辅助神器app!德州软件工具,德州wepower确实存在有挂(详细智能教程)1、许多玩家不知...
揭秘攻略!wepoke德州扑克... 揭秘攻略!wepoke德州扑克(wepower有外 挂)wepOkE(其实真的有挂)科技教程也叫必备...
wpk外 挂!德州wpk,Wp... wpk外 挂!德州wpk,WpK的确是有挂的,详细教程,(有挂攻略)1、wpk外 挂!德州wpk,W...
德州之星辅助!德州nzt实战,... 德州之星辅助!德州nzt实战,wpk德州切实有挂(详细免费辅助神器app教程)(1)德州之星辅助!德...
攻略教程!wepoke系统是免... 攻略教程!wepoke系统是免费的(wepoke透明挂黑科技)wepoKE(本来真的有挂);(需添加...
wpk透明挂(Wpk)wpk外... wpk透明挂(Wpk)wpk外 挂被实锤(透视)本来真的有挂(微扑克教程)1、上手简单,内置详细流程...
德州之星插件!德扑之星可以查数... 德州之星插件!德扑之星可以查数据,德扑之星切实真的是有挂(详细智能机器人教程);无聊就玩这款德州之星...