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

相关内容

热门资讯

最新研发!hhpoker有没有... 最新研发!hhpoker有没有作弊辅助,wepoker有没有插件,原来真的是有挂(了解有挂)1、破解...
科普!wepoker分析,如何... 科普!wepoker分析,如何下载德普之星辅助软件,总是真的有挂(竟然有挂)1、每一步都需要思考,不...
总算了解!wepoker插件下... 总算了解!wepoker插件下载,wepoker有透视底牌吗,切实真的有挂(有挂猫腻)1、操作简单,...
查到实测辅助!we-poker... 查到实测辅助!we-poker辅助器,wepoker透视脚本是什么,本来是有挂(发现有挂)1、起透看...
推荐一款!wepoker辅助器... 推荐一款!wepoker辅助器最新版本更新内容,约局吧德州真的存在透视吗,其实有挂(有挂技巧)1、起...
分享给玩家!epoker透视底... 分享给玩家!epoker透视底牌,wepoker辅助器激活码,一直有挂(确实有挂)wepoker辅助...
一分钟揭秘!哈糖大菠萝软件下载... 一分钟揭秘!哈糖大菠萝软件下载,we poker游戏下,好像真的有挂(的确有挂)1、进入游戏-大厅左...
技术分享!wepoker有没有... 技术分享!wepoker有没有透视方法,wepoker一直输的号能继续打吗,确实是真的有挂(有挂方法...
攻略讲解!哈糖大菠萝免费辅助器... 攻略讲解!哈糖大菠萝免费辅助器,wepoker辅助脚本,总是真的是有挂(有挂秘籍)小薇(辅助器软件下...
重大通报!wpk辅助是什么,a... 重大通报!wpk辅助是什么,aapoker如何设置胜率,一贯存在有挂(有挂方法)1、下载好正确养号方...