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

相关内容

热门资讯

一分钟揭秘!响水麻将辅助ai透... 一分钟揭秘!响水麻将辅助ai透视挂工具,响水麻将总是存在有开挂(有辅助挂辅教程)1.响水麻将 选牌创...
程序员教你!星火桌游辅助ai透... 程序员教你!星火桌游辅助ai透视挂脚本,星火桌游确实真的有外挂(有辅助挂助手)星火桌游是不是有人用挂...
揭秘一下!新丫丫玉溪麻将辅助a... 揭秘一下!新丫丫玉溪麻将辅助ai透视挂工具,新丫丫玉溪麻将其实是有透视挂(有辅助挂解密)1、新丫丫玉...
实测发现!忻州天天麻将辅助ai... 实测发现!忻州天天麻将辅助ai透视挂工具,忻州天天麻将一直是有开挂(有辅助挂总结)1、每一步都需要思...
一分钟快速了解!琼戏互娱辅助a... 一分钟快速了解!琼戏互娱辅助ai透视挂软件,琼戏互娱原来真的是有作弊器(有辅助挂规律)1)琼戏互娱免...
技术分享!红中麻将辅助ai透视... 技术分享!红中麻将辅助ai透视挂脚本,红中麻将都是真的有辅助器(有辅助挂工具)红中麻将能透视中分为三...
揭秘关于!亲友房辅助ai透视挂... 揭秘关于!亲友房辅助ai透视挂方法,亲友房总是是有辅助器(有辅助挂技巧)1、亲友房免费脚本咨询教程、...
玩家科普!鄱阳翻精辅助ai透视... 玩家科普!鄱阳翻精辅助ai透视挂脚本,鄱阳翻精原来是有开挂(有辅助挂方针)鄱阳翻精破解侠是真的助透视...
技巧知识分享!奈曼麻将辅助ai... 技巧知识分享!奈曼麻将辅助ai透视挂插件,奈曼麻将确实存在有透视挂(有辅助挂秘笈)该软件可以轻松地帮...
分享开挂内幕!闲来广东麻将辅助... 分享开挂内幕!闲来广东麻将辅助ai透视挂方法,闲来广东麻将原来存在有开挂(有辅助挂细节)1、金币登录...