function getTotalHeight(element) {
if (document.defaultView) {
h = element.offsetHeight
+ px2Int(getComputedStyle(element, '').getPropertyValue("padding-top"))
+ px2Int(getComputedStyle(element, '').getPropertyValue("padding-bottom"))
+ px2Int(getComputedStyle(element, '').getPropertyValue("border-top-width"))
+ px2Int(getComputedStyle(element, '').getPropertyValue("border-bottom-width"))
+ px2Int(getComputedStyle(element, '').getPropertyValue("margin-top"))
+ px2Int(getComputedStyle(element, '').getPropertyValue("margin-bottom"));
} else {
h = element.offsetHeight
+ px2Int(element.currentStyle.paddingTop)
+ px2Int(element.currentStyle.paddingBottom)
+ px2Int(element.currentStyle.borderTopWidth)
+ px2Int(element.currentStyle.borderBottomWidth)
+ px2Int(element.currentStyle.marginTop)
+ px2Int(element.currentStyle.marginBottom);
}
return h;
}
本文介绍了一个JavaScript函数,该函数用于计算HTML元素的实际总高度,包括内边距、边框、外边距等。它针对不同浏览器环境提供了兼容性处理。
111

被折叠的 条评论
为什么被折叠?



