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有透视绝活儿!AApok... WPK有透视绝活儿!AApoker万能,wpkai多功能开挂脚本该软件可以轻松地帮助玩家将AApok...
WPK四人演示!德普之星的辅助... WPK四人演示!德普之星的辅助工具介绍,微扑克ai多功能透视挂插件德普之星的辅助工具介绍能透视中分为...
WPK透视版方式!微扑克辅助下... WPK透视版方式!微扑克辅助下载,智星菠萝德州ai多功能透视脚本1、让任何用户在无需微扑克辅助下载安...
WPK软件策略!德扑软件,AA... WPK软件策略!德扑软件,AApokerai多功能开挂技巧1)德扑软件辅助插件:进一步探索德扑软件辅...
WPK下载手段!wpk辅助是什... WPK下载手段!wpk辅助是什么,微扑克ai多功能开挂方法wpk辅助是什么脚本下载中分为三种模型:w...
WPK安卓演示!aapoker... WPK安卓演示!aapoker俱乐部靠谱吗,菠萝智星德州ai多功能辅助攻略1、超多福利:超高返利,海...
WPK私人局讲义!大菠萝免费辅... WPK私人局讲义!大菠萝免费辅助,智星菠萝德州ai多功能透视挂攻略1、上手简单,内置详细流程视频教学...
WPK方法方针!aapoker... WPK方法方针!aapoker透视怎么用,菠萝智星德州ai多功能透视挂攻略亲,关键说明,aapoke...
WPK辅助器经验!wpk模拟器... WPK辅助器经验!wpk模拟器是什么,智星菠萝德州ai多功能辅助教程1、很好的工具软件,可以解锁游戏...
WPK购买手段!aapoker... WPK购买手段!aapoker插件,德扑之星ai多功能透视挂软件该软件可以轻松地帮助玩家将aapok...