@bnidev/js-utils
    Preparing search index...

    Function getElementDimensions

    • Gets the dimensions and position of a DOM element or the first element matching a CSS selector.

      Parameters

      • selectorOrElement: string | Element

        A CSS selector string or a DOM Element to measure.

      Returns
          | null
          | {
              bottom: number;
              height: number;
              left: number;
              right: number;
              top: number;
              width: number;
          }

      An object containing the width, height, top, left, right, and bottom values of the element, or null if no element is found.

      // ES Module
      import { getElementDimensions } from '@bnidev/js-utils'

      // CommonJS
      const { getElementDimensions } = require('@bnidev/js-utils')
      const dims = getElementDimensions('#my-element')
      if (dims) {
      console.log(dims.width, dims.height)
      }

      // Or with a DOM element
      const el = document.getElementById('my-element')
      const dims2 = getElementDimensions(el)
      if (dims2) {
      console.log(dims2.top, dims2.left)
      }