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

相关内容

热门资讯

推荐十款!wepoker轻量版... 推荐十款!wepoker轻量版透视方法(辅助挂)好像真的是有挂(真实有挂)1)wepoker轻量版透...
让我来分享经验!智星德州可以透... 让我来分享经验!智星德州可以透视吗(辅助挂)竟然有挂(有挂总结)1、智星德州可以透视吗免费脚本咨询教...
实测必看!大菠萝免费辅助器(辅... 实测必看!大菠萝免费辅助器(辅助挂)好像存在有挂(真的有挂)1、游戏颠覆性的策略玩法,独创攻略技巧玩...
玩家爆料!wepoker开脚本... 玩家爆料!wepoker开脚本视频(辅助挂)切实是真的有挂(有挂细节);1、该软件可以轻松地帮助玩家...
玩家必看秘籍!xpoker辅助... 玩家必看秘籍!xpoker辅助器(辅助挂)都是存在有挂(有挂方法)1.xpoker辅助器 选牌创建新...
一分钟揭秘!hhpoker是正... 一分钟揭秘!hhpoker是正品吗(辅助挂)一贯存在有挂(有挂细节)1)hhpoker是正品吗辅助插...
热点讨论!德普之星透视免费(辅... 热点讨论!德普之星透视免费(辅助挂)竟然存在有挂(有挂头条)1、很好的工具软件,可以解锁游戏的德普之...
终于懂了!德普之星透视免费(辅... 终于懂了!德普之星透视免费(辅助挂)一直存在有挂(有挂功能)一、德普之星透视免费游戏安装教程牌型概率...
我来分享!wepoker安装教... 我来分享!wepoker安装教程(辅助挂)切实真的有挂(有挂辅助)1、实时wepoker安装教程透视...
必备辅助推荐!aapoker能... 必备辅助推荐!aapoker能控制牌吗(辅助挂)一直是有挂(有挂实锤)1、进入游戏-大厅左侧-新手福...