代码拉取完成,页面将自动刷新
import isUndefined from './utils/types/isUndefined'
import isFunction from './utils/types/isFunction'
import isBoolean from './utils/types/isBoolean'
import pixel from './pixel'
import isElement from './isElement'
import _getElementSizes from './_getElementSizes'
import setStyle from './setStyle'
/**
* 获取 DOM 元素的 outerHeight 值
* ========================================================================
* @method outerHeight
* @param {HTMLElement} el
* @param {Number|String|Function|Boolean} [val]
* @param {Boolean} [includeMargin]
* @return {Number|*}
*/
const outerHeight = (el, val, includeMargin = false) => {
let height
if (!isElement(el)) {
return false
}
const {
marginTop,
marginBottom,
borderTop,
borderBottom,
paddingTop,
paddingBottom,
offsetHeight
} = _getElementSizes(el)
// val 为 Function 类型,用来获取自定义的 outerHeight
if (isFunction(val)) {
return val(el, {
marginTop,
marginBottom,
borderTop,
borderBottom,
paddingTop,
paddingBottom,
offsetHeight
})
}
// 有设置 val 参数
if (!isUndefined(val)) {
height = offsetHeight
// 获取 outerHeight,包含边距
if (isBoolean(val)) {
includeMargin = val
/* istanbul ignore else */
if (includeMargin) {
height += marginTop + marginBottom
}
return height
}
/* istanbul ignore else */
if (height !== val) {
height = val - (borderTop + borderBottom + paddingTop + paddingBottom)
// 设置 outerHeight,包含边距
/* istanbul ignore else */
if (includeMargin) {
height -= marginTop + marginBottom
}
setStyle(el, 'height', pixel(height))
}
} else {
return offsetHeight
}
}
export default outerHeight
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。