MCPcopy Create free account
hub / github.com/Barrior/JParticles / getNumberValueOfStyle

Function getNumberValueOfStyle

src/utils/dom.ts:9–21  ·  view source on GitHub ↗
(
  elem: HTMLElement,
  attr: keyof CSSStyleDeclaration
)

Source from the content-addressed store, hash-verified

7 * @param attr CSS 属性
8 */
9export 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 值

Callers 2

dom.spec.tsFile · 0.90
setCanvasDimensionFunction · 0.90

Calls 2

isStringFunction · 0.90
pIntFunction · 0.90

Tested by

no test coverage detected