Fade out animation when ng-if = false

前端 未结 1 2098
傲寒
傲寒 2021-02-19 05:24

Is there any way to animate with fade out when ng-if=\"false\" instead of instantly hide the HTML element?

I can fade-in when ng-if=\"true\" bu

1条回答
  •  无人共我
    2021-02-19 06:29

    You should use ng-animate for this. It's a native angular library that adds transition classes and a delay upon removing elements

    angular.module('app', ['ngAnimate']).
    controller('ctrl', function(){});
    .fade-element-in.ng-enter {
      transition: 0.8s linear all;
      opacity: 0;
    }
    
    .fade-element-in-init .fade-element-in.ng-enter {
      opacity: 1;
    }
    
    .fade-element-in.ng-enter.ng-enter-active {
      opacity: 1;
    }
    
    .fade-element-in.ng-leave {
      transition: 0.3s linear all;
      opacity: 1;
    }
    .fade-element-in.ng-leave.ng-leave-active {
      opacity: 0;
    }
    
    
    
    
    Click me
    SomeContent
    SomeOtherContent

    0 讨论(0)
提交回复
热议问题