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

相关内容

热门资讯

重大通报!pokermaste... 重大通报!pokermaster辅助器,wepoker模拟器哪个好用,解密教程(有挂攻略);支持多人...
透视规律!wpk模拟器多开(透... 透视规律!wpk模拟器多开(透视)一贯是有挂(详细辅助透明挂教程)1、首先打开最新版本,在首页我们可...
透视ai代打!hhpoker辅... 透视ai代打!hhpoker辅助软件下载(透视)总是是有挂(详细辅助解说技巧)1、该软件可以轻松地帮...
记者揭秘!poker辅助器免费... 1、记者揭秘!poker辅助器免费安装,wepoker透视苹果系统,技巧教程(有挂技巧)。2、pok...
透视辅助!约局吧是否有挂(透视... 透视辅助!约局吧是否有挂(透视)真是存在有挂(详细辅助揭秘教程);1、机器人多个强度级别选择2、发牌...
记者揭秘!hhpoker哪个俱... 1、记者揭秘!hhpoker哪个俱乐部靠谱,德州辅助工具到底怎么样,扑克教程(有挂攻略);详细教程。...
免费测试版!wepoker辅助... 1、免费测试版!wepoker辅助分析器,拱趴大菠萝自动计算机器人,分享教程(有挂方法)2、进入游戏...
透视新版!wepoker可以透... 透视新版!wepoker可以透视码(透视)好像有挂(详细辅助攻略教程);1、完成的残局,帮助玩家取得...
科普常识!aapoker发牌逻... 科普常识!aapoker发牌逻辑,拱趴大菠萝万能挂图解,透明挂教程(有挂技巧);人气非常高,ai更新...
透视攻略!wepoker怎么拿... 透视攻略!wepoker怎么拿到好牌(透视)真是有挂(详细辅助揭秘教程)一、AI软件牌型概率发牌机制...