当max-height设置为0时,是否可以获得元素attr高度的css值?
我需要知道要显示多少像素的元素,因为每个元素都有不同的高度,随着浏览器的大小而变化,我想从css文件中获取高度值.
解决方法:
如果通过scrollHeight属性有max-height = 0,则可以获取元素的高度.如果你设置了最小重量,它可以工作,但不是高度.
HTML:
Here you have a normal div
Something hidden is in here, but we can still get the height !
Something else here
JS:
alert(document.getElementById('toggable').scrollHeight)
CSS:
#toggable {
最大高度:0;
溢出:隐藏;
}
.other-content {
min-height: 100px;
}
标签:jquery,javascript,css,height
来源: https://codeday.me/bug/20190529/1177262.html