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

相关内容

热门资讯

重大科普!wpk俱乐部辅助器(... 重大科普!wpk俱乐部辅助器(辅助挂)竟然有挂(有挂技术辅助插件)小薇(辅助器软件下载)致您一封信;...
如何分辨真伪!如何下载wpk透... 如何分辨真伪!如何下载wpk透视版(辅助挂)原来真的是有挂(有挂攻略辅助插件)1、免费辅助多个强度级...
揭秘几款!wepoker看底牌... 揭秘几款!wepoker看底牌(辅助挂)真是是真的有挂(有挂详情辅助工具)破解侠是真的助透视。每个模...
一分钟揭秘!pokemomo辅... 一分钟揭秘!pokemomo辅助工具(辅助挂)都是是有挂(有挂存在辅助教程)能透视中分为三种模型:模...
最新技巧!wepokerplu... 最新技巧!wepokerplus脚本(辅助挂)都是是真的有挂(果真有挂辅助工具)1、游戏颠覆性的策略...
分享个大家!wepoker高级... 分享个大家!wepoker高级辅助(辅助挂)好像是真的有挂(有挂攻略辅助软件)1、模拟器是什么优化,...
教学盘点!wpk显示有作弊(辅... 教学盘点!wpk显示有作弊(辅助挂)竟然真的是有挂(有挂分享辅助方法)1、玩家可以在透视最简单三个步...
重磅来袭!wejoker内置辅... 重磅来袭!wejoker内置辅助(辅助挂)果然真的有挂(有挂头条辅助攻略)1、该软件可以轻松地帮助玩...
重大通报!wepoker怎么开... 重大通报!wepoker怎么开辅助(辅助挂)一贯真的有挂(有挂攻略辅助器)1、任何透视是真的假的的玩...
推荐十款!poker worl... 推荐十款!poker world辅助器(辅助挂)确实是有挂(真实有挂辅助教程)1)免费钻石:进一步探...