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

相关内容

热门资讯

重要通知!老友广东麻将有挂吗,... 【福星临门,好运相随】;重要通知!老友广东麻将有挂吗,werplan脚本,AI教程(有挂辅助);暗藏...
一分钟揭秘!福建兄弟13水辅助... 一分钟揭秘!福建兄弟13水辅助,wepoker有什么规律,规律教程(有挂方法);亲真的是有正版授权,...
重大推荐!广西老友有破解吗,竞... 重大推荐!广西老友有破解吗,竞技联盟破解版最新版,教你攻略(有挂分享);广西老友有破解吗免费下载原版...
玩家必备教程!四川皮皮辅助,w... 玩家必备教程!四川皮皮辅助,wepoker私人局外卦,技巧教程(有挂教程);1、不需要AI权限,帮助...
一分钟揭秘!情怀莆仙外挂,约局... 一分钟揭秘!情怀莆仙外挂,约局吧德州真的有透视挂吗,必胜教程(揭秘有挂);一、情怀莆仙外挂有挂的是的...
带你了解!雀友会潮汕图片辅助器... 带你了解!雀友会潮汕图片辅助器,wepoker俱乐部辅助,技巧教程(有挂详情)是一款可以让一直输的玩...
必备科技!天天微友第三方辅助软... 必备科技!天天微友第三方辅助软件下载,hhpoker辅助靠谱吗,曝光教程(有挂秘籍);1、天天微友第...
每日必备!逗娱碰胡辅助器,hh... 【福星临门,好运相随】;每日必备!逗娱碰胡辅助器,hhpoker透视方法,AI教程(的确有挂);暗藏...
玩家必看教程!微乐自建房怎么提... 玩家必看教程!微乐自建房怎么提高胜率,wepoker究竟有没有透视,科技教程(讲解有挂);玩家必看教...
玩家必备教程!微信边锋辅助下载... 玩家必备教程!微信边锋辅助下载,wepoker辅助器如何使用,安装教程(有挂方针);是一款可以让一直...