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可以作弊吗,h... 科普分享!wpk可以作弊吗,hhpoker德州有挂吗,原来是有挂(有人有挂)1、进入到是否有挂之后,...
玩家必看科普!wepoker手... 玩家必看科普!wepoker手机插件,hhpkoer辅助器视频,原来真的有挂(有挂讲解)1、用户打开...
玩家必看秘籍!wpk真吗,we... 玩家必看秘籍!wpk真吗,we poker免费辅助器,其实真的有挂(有挂技巧)1、有没有辅助教程、有...
玩家必看攻略!fishpoke... 玩家必看攻略!fishpoker透视,德普辅助app,竟然真的是有挂(有挂实锤)1、玩家可以在透视最...
实操分享!aapoker透视怎... 实操分享!aapoker透视怎么用,wepoker免费脚本,原来是真的有挂(有挂助手)1、进入游戏-...
我来教教你!hhpoker有后... 我来教教你!hhpoker有后台操控吗,wepoker透视最简单三个步骤,都是有挂(有挂方略)所有人...
必备教程!aapoker破解侠... 必备教程!aapoker破解侠是真的吗,微扑克游戏辅助器,切实是有挂(有挂功能)1)有没有挂:进一步...
玩家必看科普!微扑克辅助,we... 玩家必看科普!微扑克辅助,wepoker辅助器最新版本更新内容,都是是有挂(竟然有挂)1、进入到we...
最新技巧!aapoker辅助器... 最新技巧!aapoker辅助器怎么用,aapoker脚本,好像是真的有挂(有挂方式)亲,关键说明,透...
热点推荐!哈糖大菠萝攻略,红龙... 热点推荐!哈糖大菠萝攻略,红龙poker作弊指令,好像存在有挂(有挂解惑)1、热点推荐!哈糖大菠萝攻...