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
ng-show disturbing div layout - angularJS
提问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-hide
uses 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-class
attribute.
为此,您可以使用该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-class
instead so you can give the div a class which only do display:none
你应该试试,ng-class
这样你就可以给 div 一个只做的类display:none