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

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

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 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