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

相关内容

热门资讯

玩家必用!pokemmo辅助脚... 玩家必用!pokemmo辅助脚本,wpk俱乐部是真的吗,竟然真的有挂(有挂实锤)1、完成有辅助插件,...
分辨真假!wepoker有脚本... 分辨真假!wepoker有脚本吗,拱趴大菠萝开挂方法,一贯真的是有挂(存在有挂);1、用户打开应用后...
实测发现!约局吧游戏挂,wej... 实测发现!约局吧游戏挂,wejoker辅助软件,一贯有挂(有挂教学)1、破解器简单,机器人操作,插件...
玩家必看教程!hhpoker辅... 玩家必看教程!hhpoker辅助器视频,wepoker怎么增加运气,其实真的是有挂(真是有挂)1、辅...
程序员教你!werplan外卦... 程序员教你!werplan外卦神器,hhpoker外挂靠谱吗,果然真的有挂(有挂讲解)1、在插件功能...
玩家必看科普!we-poker... 玩家必看科普!we-poker辅助,wepoker轻量版有透视吗,一直存在有挂(有挂方略)1、首先打...
玩家攻略!wepoker亲友圈... 玩家攻略!wepoker亲友圈有用吗,aapoker怎么控制牌,其实存在有挂(有挂技巧)1、点击下载...
一分钟了解!fishpoker... 一分钟了解!fishpoker透视,htx矩阵wepoker辅助,切实是有挂(确实有挂)1、打开软件...
记者发布!约局吧德州透视,cl... 记者发布!约局吧德州透视,cloudpoker外挂,好像是真的有挂(有挂秘诀)1)有没有挂:进一步探...
如何分辨真伪!悟空黑桃a有挂嘛... 如何分辨真伪!悟空黑桃a有挂嘛,wepokerplus开挂,好像真的是有挂(有挂秘笈)1)辅助插件:...