1 Star 0 Fork 10

hutubaba/dom.js

Create your Gitee Account
Explore and code with more than 12 million developers,Free private repositories !:)
Sign up
Clone or Download
width.js 938 Bytes
Copy Edit Raw Blame History
Yaohaixiao authored 2023-10-12 16:04 . chore: 调整单测代码
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
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
JavaScript
1
https://gitee.com/hutu88/dom.js.git
git@gitee.com:hutu88/dom.js.git
hutu88
dom.js
dom.js
main

Search

23e8dbc6 1850385 7e0993f3 1850385