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

相关内容

热门资讯

透视插件!hhpoker透视下... 透视插件!hhpoker透视下载链接在哪里,wepoker有机器人吗,揭秘教程(一贯真的是有挂)1、...
透视存在!aapoker透视脚... 透视存在!aapoker透视脚本下载,wepoker有没有插件,可靠技巧(一贯真的是有挂);1分钟了...
透视科技!德普之星app安卓版... 《透视科技!德普之星app安卓版破解版,德普之星有辅助软件吗,2025教程(总是存在有挂)》 德普之...
透视总结!wpk辅助插件叫什么... 透视总结!wpk辅助插件叫什么,拱趴大菠萝作弊方法,2025新版(本来真的有挂);精心打造了俱乐部社...
透视苹果版!红龙poker透视... 您好,红龙poker透视工具这款游戏可以开挂的,确实是有挂的,需要了解加微【136704302】很多...
透视好牌!wpk有没有脚本,哈... 透视好牌!wpk有没有脚本,哈糖大菠萝攻略,wpk教程(最初有挂);wpk有没有脚本是一种具有地方特...
透视好友!wepoker辅助透... 1、透视好友!wepoker辅助透视软件,wepoker辅助器安装包定制,安装教程(原本是有挂);详...
透视美元局!hhpoker辅助... 透视美元局!hhpoker辅助下载,wepokerplus开挂,可靠教程(先前是有挂);一、hhpo...
透视能赢!德普之星辅助功能如何... 透视能赢!德普之星辅助功能如何打开,epoker透视底牌,2025新版教程(原来真的有挂);免费德普...
透视好牌!aapoker免费透... 1、透视好牌!aapoker免费透视脚本,拱趴大菠萝有挂吗,细节方法(一贯是有挂);详细教程。2、a...