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作弊!WePoKer工具... WPK作弊!WePoKer工具开挂ai,aa poker透视软件,本来有ai开挂妙招1、aa pok...
WPK多开!红龙扑克教程透视a... WPK多开!红龙扑克教程透视ai,wpk透视是真的吗,都是是真的有ai透视经验所有人都在同一条线上,...
WPK真假!aapoker技巧... WPK真假!aapoker技巧透视ai,如何下载德普之星辅助软件,确实有ai透视资料1、许多玩家不知...
WPK俱乐部!WPK教程辅助a... WPK俱乐部!WPK教程辅助ai,来玩app 德州 辅助,都是存在有ai辅助步骤1、来玩app 德州...
WPK工具!德扑之星app辅助... WPK工具!德扑之星app辅助器ai,来玩德州破解器,总是是有ai辅助器指南1、下载好来玩德州破解器...
WPK方法!智星菠萝德州攻略透... WPK方法!智星菠萝德州攻略透视挂ai,德扑辅助器怎么用,本来真的是有ai透视挂项目1、玩家可以在德...
WPK安卓!红龙扑克脚本辅助器... 您好,aapoker如何设置胜率这款游戏可以开挂的,确实是有挂的,需要了解加去威信【13670430...
WPK多开!德扑之星插件透视a... WPK多开!德扑之星插件透视ai,aapoker脚本,都是存在有ai透视手筋1、进入游戏-大厅左侧-...
WPK俱乐部!红龙PoKer工... WPK俱乐部!红龙PoKer工具辅助器ai,德普之星透视,一贯是真的有ai辅助器妙招1、进入到德普之...
WPK透视!智星菠萝德州教程透... WPK透视!智星菠萝德州教程透视挂ai,werplan有挂吗,其实是真的有ai透视挂绝活儿1、wer...