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脚本要领!德扑之星透视辅助软件是真的吗,微扑克ai多功能辅助器技巧一、德扑之星透视辅助软件是真...
WPK靠谱教程书!微扑克辅助,... WPK靠谱教程书!微扑克辅助,红龙PoKerai多功能透视软件1、在微扑克辅助插件功能辅助器技巧中,...
WPK安装项目!aa poke... 您好,aa poker辅助这款游戏可以开挂的,确实是有挂的,需要了解加去威信【136704302】很...
WPK辅助技法!werplan... WPK辅助技法!werplan辅助软件,德扑之星ai多功能透视挂教程小薇(辅助器软件下载)致您一封信...
WPK安装妙计!werplan... WPK安装妙计!werplan辅助软件,德州扑克ai多功能辅助器技巧所有人都在同一条线上,像星星一样...
WPK真假手筋!智星德州插件,... WPK真假手筋!智星德州插件,aapokerai多功能辅助app暗藏猫腻,小编详细说明智星德州插件破...
WPK模拟器模块!AApoke... WPK模拟器模块!AApoker脚本,WePoKerai多功能透视脚本1、WPK模拟器模块!AApo...
WPK多开法门!aapoker... WPK多开法门!aapoker能控制牌吗,红龙PoKerai多功能辅助器攻略进入游戏-大厅左侧-新手...
WPK模拟器妙计!德普之星辅助... WPK模拟器妙计!德普之星辅助器怎么用,aapokerai多功能透视app1、德普之星辅助器怎么用有...
WPK靠谱课程!wpk作弊是真... WPK靠谱课程!wpk作弊是真的吗,菠萝智星德州ai多功能辅助器技巧1、wpk作弊是真的吗免费脚本咨...