Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

224
Vistas
Add, don't replace, icon to mouse cursor

I want to add an icon to mouse when they hover html element, so that I could hint to the user, that they can right click.

I don't want to replace the default cursor, because they differ on platform and don't really need to replace the default mouse icon itself.

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You can add a mousemove event listener on the element which you want to show the custom cursor over that gets the relative x and y coordinates of the mouse to the element and applies them to the top and left style properties of the cursor:

element.addEventListener('mousemove', function(e){
  const rect = element.getBoundingClientRect();
  const [x, y] = [e.pageX - rect.left, e.pageY - Math.abs(rect.top) + window.scrollY]
  cursor.style.display = "block";
  cursor.style.left = x + "px";  
  cursor.style.top = y + "px";
})

element.addEventListener('mouseleave', function(e){
  cursor.style.display = "none"; //hide the custom cursor when they leave the element
})
#element{
  height:1200px;
  width:600px;
  background-color:black;
  position:relative;
}

#cursor{
  position:absolute;
  display:none;
  color:white;
}
<div id="element"><div id="cursor">right click!</div></div>

Keep in mind this solution requires the container element to be relatively positioned, since the cursor is absolutely positioned.

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda