Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

132
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda