javascript - AngularJS:在固定位置元素上动画 ng-show 和 ng-hide

标签 javascript html css 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.isMenuOpened true 和 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>

关于javascript - AngularJS:在固定位置元素上动画 ng-show 和 ng-hide,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62255294/

相关文章:

html - &lt;input type ="file"> 按扩展名限制可选文件

html - 我应该知道 Bootstrap 3/4 类中到底发生了什么吗?

当 url 附加 #name 时的 Javascript 函数

从 Dropdown 获取值时 JavaScript 不工作

html - 如何让浏览器识别 <url>#<anchor> 形式的已访问链接

javascript - 如何在更新卡片的弹出窗口中获取 2 个 div 值。

html - 为什么这两个div之间有差距?

javascript - 通过php或javascript读取hasoffers api生成的json数据

javascript - 使用 jQuery 检查 html 选择的值

html - iPhone 上的全屏视频播放器是否有 "onClose"事件?