简体   繁体   English

动态更改位置angular.js

[英]Change position dynamically angular.js

I have a question about dynamically changing position (bottom) in angular.js 我对在angular.js中动态更改位置(底部)有疑问

I have a div with position fixed, and I must put it on the site depends on the height of header (which is above this div). 我有一个固定位置的div,我必须将其放在网站上,具体取决于标头的高度(该标头的高度)。

Header is changed dynamically (eg you click button "add" and it adds to your header 2 lines of text, so div has a higher height), so position of my div is related to this header. 标头是动态更改的(例如,单击“添加”按钮,它会将2行文本添加到标头中,因此div的高度较高),因此div的位置与此标头有关。 How can I do this? 我怎样才能做到这一点?

Put a div around your fixed position div that has position: relative . 将div放在具有position: relative固定位置div周围。

Fixed position divs are taken out of the DOM flow and so do not take into account the position of other elements on the page. 固定位置div从DOM流中删除,因此不考虑页面上其他元素的位置。 They can be positioned relative to their parent container however. 但是,它们可以相对于其父容器定位。 So you create a parent container that wraps around your fixed div that can react to changes in the DOM, and the fixed div will then react to those changes. 因此,您将创建一个环绕固定div的父容器,该容器可以对DOM中的更改做出反应,然后固定div将对这些更改做出反应。

<header></header>
<div class="container" style="position: relative">
    <div class="fixed-position-element"></div>
</div>

您可以使用angular.element(lite jquery)来操作DOM元素。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM