AngularJS:在固定位置元素上显示和隐藏动画

阿尔文·斯特凡努斯

动画似乎无效。

<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.isMenuOpenedtrue和false设置为显示和隐藏它。

阿克伯·伊克巴尔

ng-hide类把一个display:none !important这就是为什么你没有看到动作动画...

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

下面的工作片段

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>

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章