Skip to main content

getOrCreateCanvas

Callable

  • getOrCreateCanvas(element: HTMLDivElement): HTMLCanvasElement

  • Create a canvas or returns the one that already exists for a given element. It first checks if the element has a canvas, if not it creates one and returns it. The canvas is updated for:

    1. width/height in screen pixels to completely cover the div element
    2. CSS width/height in CSS pixels to be the size of the physical screen pixels width and height (from #1) This allows drawing to the canvas and having pixel perfect/exact drawing to the physical screen pixels.

    Parameters

    • element: HTMLDivElement

      An HTML Element

    Returns HTMLCanvasElement

    canvas a Canvas DOM element