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开挂多功能插件,一贯是真的有开挂脚本模板AI 是一款可以让一直输的玩家...
WPK真假辅助器总结!wepo... WPK真假辅助器总结!wepoker代打辅助,菠萝智星德州ai多功能辅助器app1、玩家可以在wep...
必知教程开挂!博乐温州棋牌ai... 您好,必知教程开挂!博乐温州棋牌ai开挂多功能插件,素来真的有开挂助手方式这款游戏可以开挂的,确实是...
WPK透视版辅助策略!wepo... WPK透视版辅助策略!wepoker有辅助工具吗,wpkai多功能辅助软件1、wepoker有辅助工...
今日科普辅助器!顺欣棋牌ai辅... 顺欣棋牌AI 游戏攻略黑科技上线本地缓存功能,离线查阅能力开挂。提前下载对应游戏攻略数据包,断网状态...
WPK辅助器辅助器机巧!智星菠... WPK辅助器辅助器机巧!智星菠萝有挂吗,德州扑克ai多功能辅助器插件WPK辅助器辅助器机巧!智星菠萝...
揭秘真相辅助!赣南麻将ai辅助... 揭秘真相辅助!赣南麻将ai辅助多功能插件,一直存在有辅助攻略绝活是一款可以让一直输的玩家,快速成为一...
WPK控制牌透视课程!wepo... WPK控制牌透视课程!wepoker作弊方法,WePoKerai多功能透视技巧;1、起透看视 wep...
必备教程开挂!新爵互娱ai开挂... 必备教程开挂!新爵互娱ai开挂多功能插件,果然有开挂安装资料是一款可以让一直输的玩家,快速成为一个“...
WPK德州局辅助器课程!wep... WPK德州局辅助器课程!wepoker私人局可以透视,微扑克ai多功能辅助器技巧1、wepoker私...