Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

131
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!