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

169
Views
How to set a rectangle on the top center of another rectangle with pure JS

I would like to get the result like this expected. The actual problem is a div will be displayed on the top center of an icon ( behaviour like a tooltip). I have tried the following code:

const iconPosition= this.el.nativeElement.getBoundingClientRect();

const divPosition= this.div.getBoundingClientRect();

let top;
let left;

if (this.placement === 'top') {
  top = iconPosition.top - divPosition.height;
  left = iconPosition.left + (iconPosition.width - divPosition.width) / 2;
} 

The top works fine but I have an issue with the left. It leads me to this result: current

Could someone help? I got stuck for two days now. Any support is greatly appreciated! Thank you all!

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Just as an input: Can it be, that the part: (iconPosition.width - divPosition.width) / 2 is negative? So you are going to move thed upper div to the left instead to the right Math.abs(); might help, but without code......

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!