【问题标题】:ng-Animate not working for a Hide and Show settingng-Animate 不适用于隐藏和显示设置
【发布时间】:2014-05-13 21:48:56
【问题描述】:

我正在使用 AngularJS 版本 1.2.11。我已经使用 ng-Animate(显示和隐藏)设置了一个工具栏以通过过渡滑入和滑出。

这是 HTML:

 <div>
  <div class="full-height">
    <menu-main class="full-height pull-left"></menu-main>
    <menu-sub class="full-height pull-left" ng-show="data.active" ng-animate="'animate'">
    </menu-sub>
  </div>
</div>

这是同一个工具栏元素的 CSS

.animate.fade-hide, .animate..fade-show {
    -webkit-transition:all cubic-bezier(0.250, 0.460, 0.450, 0.940) 3.5s;
    -moz-transition:all cubic-bezier(0.250, 0.460, 0.450, 0.940) 3.5s;
    -o-transition:all cubic-bezier(0.250, 0.460, 0.450, 0.940) 3.5s;
    transition:all cubic-bezier(0.250, 0.460, 0.450, 0.940) 3.5s;
}
.animate.fade-hide, {
    position: fixed;
    top: 500px;
    opacity: 0.3;
}
.animate.fade-hide, .animate.fade-hide-active 
{
    position: fixed;
    top: 500px;
    opacity: 0.3;
}
.animate.fade-show {
    position: fixed;
    top: 100px;
        opacity: 1;
}
.animate.fade-show, .animate.fade-show-active {
    position: fixed;
    top: 100px;
        opacity: 1;
}

动画不起作用,我不确定我是否正确执行此操作。

【问题讨论】:

    标签: angularjs ng-animate ng-show ng-hide


    【解决方案1】:

    ng-animate 属性在 1.2 中已弃用,不再使用。相反,动画现在是基于类的。

    还要确保您引用了 angular-animate.js 并将 ngAnimate 添加为依赖模块:

    var app = angular.module('myApp', ['ngAnimate']);
    

    然后,您可以为动画命名,例如“fadein”和“fadeout”,并按照可以在 Angular documentation 中找到的特殊命名约定使用一些额外的类来装饰它们。

    关于该主题的另一个很好的来源是Year of moo

    淡入示例:

    /* After the transition this will be the only class remaining */
    .fadein {
      -webkit-transition:all cubic-bezier(0.250, 0.460, 0.450, 0.940) 1.5s;
      -moz-transition:all cubic-bezier(0.250, 0.460, 0.450, 0.940) 1.5s;
      -o-transition:all cubic-bezier(0.250, 0.460, 0.450, 0.940) 1.5s;
      transition:all cubic-bezier(0.250, 0.460, 0.450, 0.940) 1.5s;
      opacity: 1; /* Default value but added for clarity */
    }
    
    /* Initial state when showing */
    .fadein.ng-hide-remove {
      opacity: 0;
      display: block !important;
    }
    
    /* Will transition towards this state */
    .fadein.ng-hide-remove.ng-hide-remove-active {
      opacity: 1;
    }
    

    演示http://plnkr.co/edit/V9w2EwUh0unszf62TZZB?p=preview

    【讨论】:

    • 这里有一篇好文章:yearofmoo.com/2013/08/…
    • 在我的小项目中,当显示/隐藏发生时,我看不到类转换。我的意思是类转换是.ng-hide-add.ng-hide-remove。我在官方文档上观看了一段时间:docs.angularjs.org/api/ng/directive/ngShow。您知道可能是什么问题导致的吗?
    • @Dien 没有看到代码很难说。如果您可以在 plunker 中复制它或将代码邮寄给我,我可以查看(我的电子邮件在我的个人资料中)。
    • 您好,感谢您的回复。抱歉,ngAnimate 似乎没有问题,我只是发现它不会在 ngMaterial 对话框中设置动画。在对话框之外,它将按预期工作。我会先尝试自己弄清楚,以后可能需要你的帮助。谢谢:)。
    猜你喜欢
    • 1970-01-01
    • 2014-09-01
    • 2015-05-13
    • 2018-07-22
    • 2017-08-11
    • 1970-01-01
    • 2016-01-09
    • 2013-05-18
    • 2015-04-06
    相关资源
    最近更新 更多