单位相关
约 240 字小于 1 分钟
2025-04-19
一、typeof()
类型
以字符串形式返回单位类型。typeof()
的别名为 type-of()
和 type()
。
1、语法
typeof(node)
2、参数
node
: 要检查的元素
3、返回值
返回类型字符串。
4、示例
typeof(12) // => 'unit'
typeof(#fff) // => 'rgba'
type(12) // => 'unit'
type(#fff) // => 'rgba'
type-of(12) // => 'unit'
type-of(#fff) // => 'rgba'
二、unit()
单位
返回数据的单位、或者将数据转换为指定的单位。
1、语法
unit(val[, type])
2、参数
val
: 要检查的元素type
: 可选,要分配的类型
3、返回值
返回类型字符串或空字符串。
4、示例
unit(10) // => ''
unit(15in) // => 'in'
unit(15%, 'px') // => 15px
unit(15%, px) // => 15px
三、percentage()
百分比
将 num
转换为百分比。
1、语法
percentage(num)
2、参数
num
: 要处理的数字
3、返回值
返回处理后的百分比字符串。
4、示例
percentage(.5) // => 50%
percentage(4 / 100) // => 4%
更新日志
2025/8/24 08:17
查看所有更新日志
e7112
-1于