给定一个有两个元素的场景,其中第一个元素仅在满足特定条件 ng-if 时才显示,然后第二个元素将根据第一个元素是否存在而向上或向下移动。
<body ng-app="ngAnimate">
<label>Click me: <input type="checkbox" ng-model="checked" ng-init="checked=true" /></label>
<p ng-if="checked" class="variable">Variable Element</p>
<br/>
<p class="fixed">Fixed Element</p>
</body>
在固定位置显示第二个元素而不依赖于第一个元素的存在的最佳方式是什么?或者更好的是,在第一个元素可见时留出足够的空间来显示它?
到目前为止,我尝试的是通过 CSS 设置第二个元素的位置。它有效,但很可能不是最好的解决方案。
.fixed {
position: absolute;
top: 100px;
border:1px solid green;
padding:10px;
}
笨蛋here .
提前致谢!
最佳答案
您也可以尝试使用 ng-style ,例如:
<p class="fixed" ng-style="{top: checked ? '100px' : '20px'}">Fixed Element</p>
关于javascript - AngularJS ng-if 具有固定元素位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30915428/