@schema-render/search-table-react
Version:
Conditional search table component.
31 lines (30 loc) • 901 B
JavaScript
import { utils } from "@schema-render/core-react";
const { isString } = utils;
/**
* 计算元素高度,包含 margin 值
* @param element DOM 元素
* @returns 高度
*/ export function calcOuterHeight(element) {
if (!element) {
return 0;
}
const style = window.getComputedStyle(element, null);
const margin = parseFloat(style.marginTop) + parseFloat(style.marginBottom);
return element.offsetHeight + margin;
}
/**
* 获取元素属性值,并转换成数字类型
* @param element DOM 元素
* @param attr 属性
*/ export function getNumericStyleValue(element, attr) {
if (!element || !attr) {
return 0;
}
const style = window.getComputedStyle(element, null);
const value = style[attr];
// 数字类型字符串才做处理
if (isString(value) && value.match(/^\d+/)) {
return parseFloat(value);
}
return 0;
}