1
window.addEventListener("resize", getSize);
function getSize(){
var node = document.getElementById('sample');
var height = node.style.height;
console.log('height: ', height);//expect 100px, get nothing
}
#sample {
padding: 20px;
height: 100px;
overflow-y: auto;
border: solid blue;
margin: 10px 300px 10px 25px;
position: 'relative'
}
node.style.height
的高度总是空/空。请注意,我将高度设置为100px。为什么?我怎样才能获得节点的CSS高度?
使用'节点。 offsetHeight'。 –
或node.clientHeight – n0m4d
请注意,您仍然需要使用'node.style.height ='1000px';'来设置值。设置'offsetHeight'不起作用。 –