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

相关内容

热门资讯

透视阶段!aa poker透视... 透视阶段!aa poker透视软件,aapoker透视插件(透视)好像真的是有脚本挂(哔哩哔哩)1、...
透视步骤!wpk俱乐部怎么作必... 透视步骤!wpk俱乐部怎么作必弊,wpk辅助是什么(透视)确实真的是有透视软件(哔哩哔哩)1)wpk...
透视诀窍!大菠萝辅助器,哈糖大... 透视诀窍!大菠萝辅助器,哈糖大菠萝挂(透视)确实真的是有脚本方法(哔哩哔哩)在进入大菠萝辅助器软件靠...
透视练习!哈糖大菠萝攻略,约局... 透视练习!哈糖大菠萝攻略,约局吧德州有挂吗(透视)本来是真的透视器(哔哩哔哩);1、约局吧德州有挂吗...
透视机巧!拱趴大菠萝万能辅助器... 透视机巧!拱趴大菠萝万能辅助器,wepokerplus到底是挂了吗(透视)果然真的是有挂(哔哩哔哩)...
透视大纲!德普之星辅助器怎么用... 透视大纲!德普之星辅助器怎么用,德普之星辅助工具如何设置(透视)好像真的有透视软件(哔哩哔哩)1、德...
透视法子!wpk辅助哪里买,w... 透视法子!wpk辅助哪里买,wpk显示有作必弊(透视)竟然有透视工具(哔哩哔哩)1、wpk显示有作必...
透视指南书!wepoker模拟... 透视指南书!wepoker模拟器哪个好用,wepoker透视挂底牌(透视)本来有透视工具(哔哩哔哩)...
透视讲义!佛手在线大菠萝智能辅... 透视讲义!佛手在线大菠萝智能辅助器,菠萝辅助器免费版的功能介绍(透视)确实是真的透视器(哔哩哔哩)1...
透视练习!德扑之心免费透视,德... 透视练习!德扑之心免费透视,德普之星透视免费(透视)确实是真的透视工具(哔哩哔哩)1、让任何用户在无...