我正在使用 Angular 5,在组件中我有一个方法
onFullScreen : function (event){ console.log(event[0]) }
在这里,当我执行console.log(event[0])
时,这将返回这个
这会返回一个 HTMLDivElement,现在我想在 onFullScreen()
方法中获取高度属性。如何获得?
最佳答案
获取元素高度(以及许多其他布局相关属性)的最佳方法是使用 getBoundingClientRect
( https://developer.mozilla.org/en-US/docs/Web/API/Element/getBoundingClientRect )。
所以你可以这样做:
const height = event[0].getBoundingClientRect().height;
关于html - 如何从html div元素获取高度?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49726852/