Alvin Stefanus
Alvin Stefanus

Reputation: 2153

AngularJS: Animate ng-show and ng-hide On Fixed Position Element

The animation does not seem to work.

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

Here is my 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;
    }

I just set the $scope.isMenuOpened true and false to display and hide it.

Upvotes: 2

Views: 123

Answers (1)

Akber Iqbal
Akber Iqbal

Reputation: 15031

The ng-hide class puts a display:none !important which is why you don't see the animation in action...

to simulate the transition, I have created a my-ng-hide class which takes us to max-width :0px that you intended. Press the button to toggle it and see the behavior;

working snippet below:

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>

Upvotes: 2

Related Questions