javascript ng-show 令人不安的 div 布局 - angularJS

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/23060869/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-28 00:15:19  来源:igfitidea点击:

ng-show disturbing div layout - angularJS

javascriptcssangularjssingle-page-applicationng-show

提问by FootsieNG

I am using ng-show="!notesOpened"to hide a div if the notesOpened variable is true. However when hidden it messes up layout. Is there a way to make ng-show act in the same way as the css property visibility:hidden? so that all div elements around the div being hidden stay in the same place

ng-show="!notesOpened"如果 notesOpened 变量为真,我将使用隐藏 div。但是,当隐藏时,它会弄乱布局。有没有办法让 ng-show 以与 css 属性相同的方式运行visibility:hidden?以便隐藏的 div 周围的所有 div 元素保持在同一位置

回答by Pooja Shah

ng-hideuses the same property that you're referring to, i.e. display: none.

ng-hide使用您所指的相同属性,即display: none.

If you need to achieve this, you need to use visibility: hidden;

如果你需要实现这一点,你需要使用 visibility: hidden;

For that you can use the ng-classattribute.

为此,您可以使用该ng-class属性。

eg: ng-class="{'vis-hidden': notesOpened==true}"

例如: ng-class="{'vis-hidden': notesOpened==true}"

  .vis-hidden{
     visibility: hidden;
  }

回答by Himanth Kumar

I have got this working

我有这个工作

ng-style="{visibility: notesOpened && 'visible' || 'hidden'}"

ng-style="{visibility: notesOpened && 'visible' || 'hidden'}"

回答by Fuzzyma

You should try ng-classinstead so you can give the div a class which only do display:none

你应该试试,ng-class这样你就可以给 div 一个只做的类display:none