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

194
Views
get poistion of mouse pointer in a box which have child elements

i want to get position of mouse pointer than the a box

for example :

 !

I need this space but if the mouse enters the red or yellow box i get another number.

i know we have e.offsetY but this give the position than e.target so if the box have a child this dont work

i know too we have e.layerY but this give the position than relative so if the child element have relative position style ot transform its not work true

for example :

const parent = document.querySelector(".parent");
const result = document.querySelector(".result");


parent.addEventListener("mousemove",(e)=>{
result.innerText = `offsetY: ${e.offsetY} , layerY: ${e.layerY}`})
.parent{
width:200px;
height:200px;
background-color:blue;
padding:30px;
position:rlative
}

.result{
background-color:#999;
color:black;
padding:10px;
margin:20px;
}


.child-red{

background-color:red;
width:30px;
height:30px;

}


.child-yellow{
background-color:yellow;
width:30px;
height:30px;
margin-top:30px;
position:relative
<div class="parent">

  <div class="child-red">
  
  </div>
  
  
   <div class="child-yellow">
  
  </div>

</div>


<p class="result">offsetY: 0 , layerY: 0</p>

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

0

offsetY as it says in the name gives you the offset of the cursor inside of an element, If you want the cursor co-ordinates in px values with respect to the document.body you need event.cursorY

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!