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

相关内容

热门资讯

一起来讨论!hhpoker是内... 一起来讨论!hhpoker是内部控制吗,aapoker透视怎么用,总是真的有挂(有挂工具)该软件可以...
值得注意的是!菠萝德州透视脚本... 值得注意的是!菠萝德州透视脚本,德扑圈透视,原来真的有挂(有挂总结)暗藏猫腻,小编详细说明德扑圈透视...
我来分享!哈糖大菠萝开挂,we... 您好,这款游戏可以开挂的,确实是有挂的,需要了解加去威信【136704302】很多玩家在这款游戏中打...
随着!wepoker辅助分析器... 随着!wepoker辅助分析器,德扑之心免费透视,其实真的有挂(有挂讲解)1、德扑之心免费透视辅助软...
推荐一款!如何下载wpk透视版... 推荐一款!如何下载wpk透视版,德普之星辅助器,都是真的是有挂(有挂详情)1、首先打开德普之星辅助器...
受玩家影响!wepoker免费... 受玩家影响!wepoker免费脚本弱密码,德普软件,总是是真的有挂(今日头条)该软件可以轻松地帮助玩...
玩家实测!hhpoker辅助挂... 玩家实测!hhpoker辅助挂是真的吗,哈糖大菠萝挂,切实是真的有挂(有挂详情)是不是有人用挂微扑克...
黑科技辅助挂!hhpoker真... 黑科技辅助挂!hhpoker真的有透视吗,德扑圈透视,本来存在有挂(确实有挂)一、德扑圈透视游戏安装...
一分钟揭秘!wepoker透视... 一分钟揭秘!wepoker透视脚本免费使用视频,werplan怎么作弊,总是是有挂(有挂细节)透视方...
记者获悉!we poker辅助... 记者获悉!we poker辅助器下载,德扑之星透视软件免费入口官网,本来真的有挂(真的有挂)运德扑之...