( elem: HTMLElement, attr: keyof CSSStyleDeclaration )
| 7 | * @param attr CSS 属性 |
| 8 | */ |
| 9 | export function getNumberValueOfStyle( |
| 10 | elem: HTMLElement, |
| 11 | attr: keyof CSSStyleDeclaration |
| 12 | ): number | void { |
| 13 | const value = window.getComputedStyle(elem)[attr] |
| 14 | if (isString(value)) { |
| 15 | // 匹配字符串的数字字符 |
| 16 | const numberValue = (value as string).match(/\d+/) |
| 17 | if (numberValue) { |
| 18 | return pInt(numberValue[0]) |
| 19 | } |
| 20 | } |
| 21 | } |
| 22 | |
| 23 | /** |
| 24 | * 获取 DOM 元素距离页面的 top、left 值 |
no test coverage detected