weex-ui-demo
Version:
A rich interaction, lightweight, high performance UI library based on Weex
36 lines (33 loc) • 910 B
JavaScript
// px字符串转rem字符串
function px2Rem (pxStr) {
if (!pxStr) return '0rem'
let pxNum = parseInt(pxStr.split('px')[0])
let remStr = `${(pxNum / 75)}rem`
return remStr
}
// px字符串转rem字符串
function hex2Rgb (hexColor) {
// 十六进制颜色值的正则表达式
let reg = /^#([0-9a-fA-f]{3}|[0-9a-fA-f]{6})$/
// 如果是16进制颜色
if (hexColor && reg.test(hexColor)) {
if (hexColor.length === 4) {
let hexColorNew = '#'
for (let i = 1; i < 4; i += 1) {
hexColorNew += hexColor.slice(i, i + 1).concat(hexColor.slice(i, i + 1))
}
hexColor = hexColorNew
}
// 处理六位的颜色值
let hexColorChange = []
for (let i = 1; i < 7; i += 2) {
hexColorChange.push(parseInt('0x' + hexColor.slice(i, i + 2)))
}
return 'RGB(' + hexColorChange.join(',') + ')'
}
return hexColor
}
export {
px2Rem,
hex2Rgb
}