2017-08-29 138 views
0

我有一个使用纳米滚动条的指令,它应该有一些固定的高度。 的结构是这样的:检查父母div是否有高度

<div id="parent_div"> 
    <my-custom-directive> 
     <div>...</div> 
     <div id="div_required_to_have_fixed_height">...</div> 
    </my-custom-directive> 
</div> 

我想有在DIV一些固定的高度与ID- div_required_to_have_fixed_height。样式高度参数可以在第一个div处提供,编号为 - parent_div。 因此,在格div_required_to_have_fixed_height,我要检查,如果出现在母公司层面的高度,然后使用以其他方式使用高度:500像素

反正有没有做到这一点使用角/ CSS。

+0

你可以选择使用jQuery'$( '#div_required_to_have_fixed_height')最接近( '#parent_div')的CSS('高度固定高度的div的父母heigth。 ')' –

+0

不能使用这个,因为在我的自定义指令有没有父母div id的信息 – Anita

回答

0

您可能会发现的offsetHeight有用:

var element = document.getElementbyId("div_required_to_have_fixed_height"); 
var height = element.offsetHeight; 
+0

我不知道为什么,但这是给错误 - element.offsetHeight()不是一个函数 – Anita

+0

我的坏,它是一个属性,而不是一个功能。应该检查。使用offsetHeight。 – udbhavs

0

来完成你在找什么,我会建议您尝试了min-height CSS属性。

在你的情况min-height:500px;

在这一点,你可以在DOMContentLoaded添加事件侦听器,以确定是否需要高度的调节。

喜欢的东西:

document.addEventListener("DOMContentLoaded", function(event) { 
    console.log("DOM fully loaded and parsed"); 
    //here you can invoke a function to check the parent div 
});