Fetch the repository succeeded.
import isNumber from './utils/types/isNumber'
import isString from './utils/types/isString'
import isUndefined from './utils/types/isUndefined'
import isElement from './isElement'
import setStyle from './setStyle'
import offset from './offset'
/**
* 获取或设置 DOM 元素的宽度。
* ========================================================================
* @method width
* @param {HTMLElement} el
* @param {Number|String} [val]
* @return {Number|*}
*/
const width = (el, val) => {
let value
/* istanbul ignore else */
if (
!isElement(el) ||
(!isUndefined(val) && !isNumber(val) && !isString(val))
) {
return false
}
if (isUndefined(val)) {
return offset(el).width
} else {
if (isNumber(val)) {
value = `${val}px`
} else {
value = `${val.replace(/\D/gi, '')}px`
}
setStyle(el, 'width', value)
}
}
export default width
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。