AngularJS ng-class JavaScript animations不会触发

AngularJS ng-class javascript animations doesn't trigger

本文关键字:animations ng-class JavaScript AngularJS      更新时间:2023-09-26

我正在尝试使用添加和删除通过通常的语法将 js 定义的动画附加到 ng-class 指令,但动画不会运行。日志记录显示不会调用添加和删除函数。

app.animation( ".bob", function () {
    return {
        add : function ( element, done ) {
            // Do add animation here and call done when done.
        },
        remove : function ( element, done ) {
            // Do remove animation here and call done when done.
        }
    }
} );

这通常适用于其他指令,例如 ngIf 及其进入和离开动画,但对于 ngClass,它似乎仅适用于 css 动画,正如文档中的示例所证明的那样

你需要使用addClass和removeClass而不是add/remove。此外,您还需要三个参数(元素,类名,完成),您缺少第二个参数。