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

相关内容

热门资讯

终于清楚!鸿狐大厅脚本,pok... 终于清楚!鸿狐大厅脚本,pokerrrr2辅助,线上教程(有挂总结);相信小伙伴都知道这个鸿狐大厅脚...
免费测试版!灯笼众娱脚本,微扑... 免费测试版!灯笼众娱脚本,微扑克辅助下载,曝光教程(详细教程);人气非常高,ai更新快且高清可以动的...
盘点几款!天天微友第三方辅助软... 盘点几款!天天微友第三方辅助软件下载,hhpoker辅助靠谱吗,规律教程(有挂透视)是一款可以让一直...
玩家必看分享!微信小程序跑得快... 玩家必看分享!微信小程序跑得快辅助脚本,aa poker辅助,技巧教程(有挂教程);是一款可以让一直...
一分钟揭秘!潮汕鱼虾蟹app源... 一分钟揭秘!潮汕鱼虾蟹app源码,购买的wpk辅助在哪里下载,黑科技教程(详细教程);一分钟揭秘!潮...
今日头条!胡易辅助软件,wep... 【福星临门,好运相随】;今日头条!胡易辅助软件,wepoker一直输的号能继续打吗,可靠技巧(真实有...
必备科技!微乐小程序微乐房间怎... 必备科技!微乐小程序微乐房间怎么开挂,wepoker透视脚本安卓,必赢教程(有挂教程);人气非常高,...
揭秘真相!情怀大陆dnf辅助,... 揭秘真相!情怀大陆dnf辅助,佛手在线大菠萝辅助,AI教程(有挂细节);相信小伙伴都知道这个佛手在线...
玩家必看教程!赣牌圈小程序破解... 玩家必看教程!赣牌圈小程序破解版,hhpoker德州透视,黑科技教程(有挂细节);赣牌圈小程序破解版...
最新研发!微信小程序辅助app... 您好:微信小程序辅助app下载这款游戏可以开挂的,确实是有挂的,很多玩家在这款游戏中打牌都会发现很多...