加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

angularjs – 当元素最初被隐藏时,角度动画在第一次运行时无法正

发布时间:2020-12-17 10:18:21 所属栏目:安全 来源:网络整理
导读:我在我的角度应用程序上连接一个状态栏,目的是当向服务器发出请求时,栏会显示响应消息,将有一个背景颜色来表示成功或错误,以及是否成功隐藏之后几秒钟. 我所看到的是,在加载页面后第一次运行此逻辑时,动画未运行(淡入和定时淡出都无法运行),但仅当状态栏元素
我在我的角度应用程序上连接一个状态栏,目的是当向服务器发出请求时,栏会显示响应消息,将有一个背景颜色来表示成功或错误,以及是否成功隐藏之后几秒钟.

我所看到的是,在加载页面后第一次运行此逻辑时,动画未运行(淡入和定时淡出都无法运行),但仅当状态栏元素最初被隐藏时,如果我设置在页面加载时ng-show变量为true所有动画都按预期工作.

我确实通过chrome的开发人员工具检查了源代码,并且在第一次运行期间,div具有这些类alert-bar ng-hide-remove ng-hide-remove-active alert-bar-success ng-animate ng-hide在动画应该具有之后已经完成了.当动画确实有效时,唯一存在的类是alert-bar alert-bar-success ng-animate ng-hide.

HTML:

<div class="alert-bar" ng-show="response.show"  ng-class="(response.result == true) ? 'alert-bar-success' : 'alert-bar-danger'">
    <div class="container">
        <label>Message: {{response.message}}</label>
    </div>
</div>

CSS:

.alert-bar {
    width: 100%;
    margin-top: -20px;
    margin-bottom: 20px;
}

.alert-bar-success {
    background-color: #5cb85c;
    border-color: #4cae4c;
    color: #ffffff;
}

.alert-bar-danger {
    color: #ffffff;
    background-color: #d9534f;
    border-color: #d43f3a;
}

.alert-bar.ng-hide-add,.alert-bar.ng-hide-remove {
  -webkit-transition:all linear 0.3s;
  -moz-transition:all linear 0.3s;
  -o-transition:all linear 0.3s;
  transition:all linear 0.3s;
  display:block!important;
}

.alert-bar.ng-hide-add.ng-hide-add-active,.alert-bar.ng-hide-remove {
  opacity:0;
}

.alert-bar.ng-hide-add,.alert-bar.ng-hide-remove.ng-hide-remove-active {
  opacity:1;
}

控制者:

controllers.controller("AppController",['$scope','$timeout',function($scope,$timeout) {
    $scope.response = {};

    $scope.response.received = function(message,result) {
        $scope.response.message = message;
        $scope.response.result = result;
        $scope.response.show = true;
        if (result == true) {
            $timeout(function () {
                $scope.response.show = false;
            },4000);
        }
    };
}]);
这是因为应用于ng-class和ng-hide指令的动画代码之间的相互作用.我做这样的工作的唯一方法是使用单独的< div>有条件地显示/隐藏但具有静态类的元素.

这是一个plunkr,演示将上面分成两个< div>元素为问题中的问题创建一个工作示例:

http://plnkr.co/edit/PFNGkOLKvs8Gx9h1T6Yk?p=preview

或者,您可以完全放弃使用ng-hide / ng-show并专门使用ng-class.

编辑:有关仅使用ng-class的版本,请参阅http://plnkr.co/edit/JiLPc6cqiLHR21c64cCy?p=preview.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读