Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

133
Vistas
Confused about getBoundingClientRect

Confused about the getBoundingClientRect() function in Javascript.

According to the official document, if const rect = getBoundingClientRect();, then we have

rect.width = rect.right - rect.left;

rect.height = rect.bottom - rect.top;

Does it means the left right position are left inclusive and right exclusive, i.e. [left, right)? Otherwise it should be

rect.height = rect.bottom - rect.top + 1;

Look at the following 5x5 map. In [inclusive, inclusive] mode, the bounding rect all the 1s should be left=2, right=4, top=3, bottom=4, and we have

width=right-left+1=4-2+1
height=bottom-top+1=4-3+1

5x5 Grid

0 0 0 0 0
0 0 0 0 0
0 0 0 0 0
0 0 1 1 1
0 0 1 1 1

A more specified question:

what does rect.left mean? Does it mean that the distance to left of client container or the ith pixel? What about rect.right?

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Consider it this way :

enter image description here

If the gray square represents screen space, then the red square has bounding box :

{
  x: 1, y: 1,
  width: 3, height: 3
}

Which means that it has left=1, right=4, and therefore, right-left=width

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda