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

175
Views
Cambiar la posición del elemento al lado del cursor

Bueno entonces tengo esto:

 x = `${e.clientX+window.scrollX}px` y = `${e.clientY+window.scrollY}px`

Y funciona, pero el problema es que el elemento puede extenderse fuera de la página y crea una barra de desplazamiento.
Entonces, ¿cómo puedo hacer que posicione el div de alguna manera que no haga eso? ¿Es posible?

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

0

Traté de resolver esto a través de JS. Aquí está mi código:

 var pointerX = -1; var pointerY = -1; document.onmousemove = function(event) { pointerX = event.pageX; pointerY = event.pageY; } setInterval(pointerCheck, 1000); function pointerCheck() { console.log('Cursor at: '+pointerX+', '+pointerY); }
about 4 years ago · Juan Pablo Isaza Report

0

Puede tener en cuenta el ancho/alto de la ventana gráfica y el ancho/alto del elemento para calcular las coordenadas x/y de su elemento. Vea el pseudocódigo adjunto para hacerse una idea. Podría necesitar un ajuste aquí y allá :)

 const { clientHeight, clientWidth } = document.documentElement const { offsetHeight, offsetWidth } = element const { clientY, clientX } = event const { scrollY, scrollX } = window let x = clientX + scrollX // check if the box would leave the viewport on the right side if (x + offsetWidth > clientWidth) { // move the element to the left x -= clientWidth - (x + offsetWidth) } let y = clientY + scrollY // check if the box would leave the viewport on the bottom if (y + offsetHeight > clientHeight) { // move the element to the top y -= clientHeight - (y + offsetHeight) }
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!