20 lines
681 B
JavaScript
20 lines
681 B
JavaScript
// 获取盒子的高度和上下边距之和
|
|
function getBoxHeight(box) {
|
|
if (!box) return 0
|
|
const styles = window.getComputedStyle(box)
|
|
const height = parseFloat(styles.height)
|
|
const marginTop = parseFloat(styles.marginTop)
|
|
const marginBottom = parseFloat(styles.marginBottom)
|
|
return height + marginTop + marginBottom
|
|
}
|
|
// 获取盒子的上下内边距之和
|
|
function getBoxPadding(box) {
|
|
if (!box) return 0
|
|
const styles = window.getComputedStyle(box)
|
|
const paddingTop = parseFloat(styles.paddingTop)
|
|
const paddingBottom = parseFloat(styles.paddingBottom)
|
|
return paddingTop + paddingBottom
|
|
}
|
|
export {
|
|
getBoxHeight, getBoxPadding
|
|
} |