Function getFromStyles

  • Returns a CSS variable from a CSS style declaration, or returning fallback.

    // These will all access --my-var
    getFromStyles(getComputedStyle(element), `--my-var`, `red`);
    getFromStyles(getComputedStyle(element), `my-var`, `red`);
    getFromStyles(getComputedStyle(element), `my_var`, `red`);

    Type Parameters

    • T extends string | number

    Parameters

    • styles: CSSStyleDeclaration
    • name: string
    • fallback: T

    Returns T