Skip to main content

BoundingClientRectCache

Cache for bounding client rectangles. This is useful when cost of HTMLElement.getBoundingClientRect() becomes a problem (it causes browser reflow which in some situations can be very costly). By caching the information from the DOMRect, this cost can be avoided.

Index

Constructors

Methods

Constructors

constructor

Methods

publicgetOrAdd

  • getOrAdd(element: HTMLElement, timeInMsToNextRefresh?: number): DOMRectCached
  • Get or add a DOMRectCached instance for a specified element.


    Parameters

    • element: HTMLElement

      HTMLElement to get a DOMRectCached instance for.

    • timeInMsToNextRefresh: number = 300

      Optional. Defaults to 300. If the instance, returned by this method, already exists in the cache. Then DomRectCached.refresh method on the instance is called automatically if

      1. timeInMsToNextRefresh = 0. Useful when DomRectCached should be refreshed immediatly.
      2. timeInMsToNextRefresh > 0 && performance.now() - instance.lastRefreshInMs > timeInMsToNextRefresh

      This means that if timeInMsToNextRefresh < 0 then DomRectCached.refresh will never be called. This can be useful when we never want to refresh the DomRectCached instance.

    Returns DOMRectCached

    A DOMRectCached element.