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,AApoker软件,都是真的有ai辅助器方案亲,关键说明,...
WPK四人!wpk脚本辅助ai... WPK四人!wpk脚本辅助ai,AApoker软件,原来是有ai辅助经验AApoker软件是不是有人...
WPK模拟器!微扑克插件透视a... WPK模拟器!微扑克插件透视ai,德扑圈透视,一贯真的是有ai透视要领一、德扑圈透视可以开透视的定义...
WPK软件!红龙扑克工具辅助器... WPK软件!红龙扑克工具辅助器ai,菠萝辅助器免费版的特点,好像真的是有ai辅助器举措亲,关键说明,...
WPK模拟器!德州扑克软件辅助... WPK模拟器!德州扑克软件辅助ai,aapoker透视脚本,竟然真的是有ai辅助机巧1、打开软件启动...
WPK靠谱!wpk插件透视挂a... WPK靠谱!wpk插件透视挂ai,pokerworld修改器,原来真的有ai透视挂举措暗藏猫腻,小编...
WPK俱乐部!WePoKer工... WPK俱乐部!WePoKer工具辅助器ai,智星菠萝透视,确实存在有ai辅助器妙招1、智星菠萝透视辅...
WPK靠谱!aapoker工具... WPK靠谱!aapoker工具透视挂ai,拱趴大菠萝怎么开挂,本来真的有ai透视挂法子1、进入游戏-...
WPK购买!德扑之星教程开挂a... WPK购买!德扑之星教程开挂ai,aapoker插件,总是真的是有ai开挂手段1、下载好aapoke...
WPK靠谱!WPK脚本开挂ai... WPK靠谱!WPK脚本开挂ai,佛手大菠萝13道挂哪里,切实是真的有ai开挂阶段;1、让任何用户在无...