【问题标题】:AngularJS: Animate ng-show and ng-hide On Fixed Position ElementAngularJS:在固定位置元素上动画 ng-show 和 ng-hide
【发布时间】:2020-06-13 11:55:52
【问题描述】:

动画似乎不起作用。

<div ng-cloak class="customize-modal text-white" ng-show="isMenuOpened == true">
    ...
</div>

这是我的 CSS:

.customize-modal {
    position: fixed;
    left: 0;
    top: 50%;
    transform: translateY(-50%);
    background: rgba(0, 0, 0, 0.8);
    max-width: 100vw;
    max-height: 100vh;
    overflow: scroll;
    padding: 10px;
    -webkit-transition: max-width 0.5s linear;
    -moz-transition: max-width 0.5s linear;
    -o-transition: max-width 0.5s linear;
    transition: max-width 0.5s linear;
}

    .customize-modal.ng-hide {
        max-width: 0px;
    }

我只是设置了$scope.isMenuOpened true 和 false 来显示和隐藏它。

【问题讨论】:

  • 尝试使用 ng-if 代替 ng-show
  • 同样的结果没有动画
  • 尝试将 isMenuOpened 放入一个对象中,然后尝试例如$scope.info={isMenuOpened :false};
    ...

标签: javascript html css angularjs


【解决方案1】:

ng-hide 类放置了一个 display:none !important,这就是为什么您看不到动画的原因...

为了模拟转换,我创建了一个 my-ng-hide 类,它将我们带到您想要的 max-width :0px。按下按钮进行切换并查看行为;

在下面工作sn-p

var app = angular.module('myApp', []);
app.controller('myCtrl', function($scope) {
  $scope.addAClass = function() {
    ($scope.myVar) ? $scope.myVar = false: $scope.myVar = true;
  }
});
.customize-modal {
  position: fixed;
  left: 0;
  top: 50%;
  transform: translateY(-50%);
  background: rgba(0, 0, 0, 0.8);
  width: 70vw;
  max-width: 100vw;
  max-height: 100vh;
  overflow: scroll;
  padding: 10px;
  -webkit-transition: max-width 0.5s linear;
  -moz-transition: max-width 0.5s linear;
  -o-transition: max-width 0.5s linear;
  transition: max-width 0.5s linear;
}

.customize-modal.my-ng-hide {
  max-width: 0px;
}
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.9/angular.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>

<div ng-app="myApp" ng-controller="myCtrl" ng-init="myVar = false">
  <div id='normal' class="customize-modal " ng-class="(myVar) ? 'my-ng-hide' : ''"> </div>
  <button type="button" id="myBtn" ng-click="addAClass()"> my-ng-hide class is added? {{myVar}} ... click to toggle</button>
</div>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-12-08
    • 2014-03-27
    • 2015-01-30
    • 1970-01-01
    • 1970-01-01
    • 2015-06-29
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多