3 Star 54 Fork 14

Yaohaixiao / dom.js

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
getColor.js 878 Bytes
一键复制 编辑 原始数据 按行查看 历史
Yaohaixiao 提交于 2023-10-12 16:04 . chore: 调整单测代码
import isString from './utils/types/isString'
import getStyle from './getStyle'
import toHex from './toHex'
import toRGB from './toRGB'
import isElement from './isElement'
import { COLOR_PROPS } from './utils/enum'
/**
* 获取DOM 元素 attr 指定的颜色属性值,可以指定 16 进制或者 RGB 格式
* ========================================================================
* @method getColor
* @since 0.4.0
* @param {HTMLElement} el
* @param {String} attr
* @param {Boolean} [isHex]
* @return {String|Boolean}
*/
const getColor = (el, attr, isHex = true) => {
let color
if (!isElement(el) || !isString(attr) || COLOR_PROPS.indexOf(attr) === -1) {
return false
}
color = getStyle(el, attr)
if (!color) {
return 'transparent'
}
return isHex ? toHex(color) : toRGB(color)
}
export default getColor
JavaScript
1
https://gitee.com/yaohaixiao/dom.js.git
git@gitee.com:yaohaixiao/dom.js.git
yaohaixiao
dom.js
dom.js
main

搜索帮助