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

218
Views
¿Cómo puedo cambiar las propiedades del cursor cuando no está en uso?

Estoy tratando de lograr un efecto visual con JavaScript y CSS para desvanecer un simple cursor personalizado cuando no se mueve. Ni siquiera sé si tal efecto es posible, pero creo que a través de Keyframes o JavaScript puede ser posible con un poco de ayuda.

Esto es lo que tengo hasta ahora:

 var cursor = document.getElementById("cursor"); document.body.addEventListener("mousemove", function(e) { cursor.style.left = e.clientX + "px", cursor.style.top = e.clientY + "px"; });
 * { padding: 0; margin: 0; border: 0; } html, body { width: 100%; height: 100%; min-height: 100%; background: #e8e8e8; cursor: none; } .inactive-fade-out { transition: fadeout 150ms ease-out; } @keyframes fadeout { from { opacity: 1; } to { opacity: 0.1; } } #cursor { position: fixed; border-radius: 50%; transform: translateX(-50%) translateY(-50%); left: -100px; top: 50%; background-color: black; height: 8px; width: 8px; transition: all 150ms ease-out; }
 <div id="cursor" class="inactive-fade-out"></div>

Objetivo:

  • Logre el efecto de atenuar el cursor cuando no se mueve en la ventana gráfica con CSS o JavaScript

Puntos extra:

  • Evite (si es posible) el uso de bibliotecas externas como jQuery

¡Su ayuda es muy apreciada!

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

0

Puede usar clearTimeout y setTimeout para esto

 var timeout; var cursor = document.getElementById("cursor"); document.body.addEventListener("mousemove", function(e) { cursor.style.left = e.clientX + "px", cursor.style.top = e.clientY + "px"; cursor.style.opacity = 1; clearTimeout(timeout); timeout = setTimeout(function() { cursor.style.opacity = 0; }, 500); });
 * { padding: 0; margin: 0; border: 0; } html, body { width: 100%; height: 100%; min-height: 100%; background: #e8e8e8; cursor: none; } .inactive-fade-out { transition: fadeout 150ms ease-out; } @keyframes fadeout { from { opacity: 1; } to { opacity: 0.1; } } #cursor { position: fixed; border-radius: 50%; transform: translateX(-50%) translateY(-50%); left: -100px; top: 50%; background-color: black; height: 8px; width: 8px; transition: all 150ms ease-out; }
 <div id="cursor" class="inactive-fade-out"></div>

about 4 years ago · Juan Pablo Isaza Report

0

La forma en que lo hice es:

Cada vez que se mueve el mouse, se establece una variable con una marca de tiempo de cuando se movió el mouse. Un bucle monitorea esta marca de tiempo y verifica si han pasado más de 500 ms desde que se movió el cursor y lo oculta. De lo contrario, lo muestra.

Aquí está el fragmento

 var cursor = document.getElementById("cursor"); var last_move_timestamp = Date.now(); var loop = setInterval(function() { if (Date.now() - last_move_timestamp > 500) { document.getElementById('cursor').style.opacity = 0; } else { document.getElementById('cursor').style.opacity = 1; } }, 10); document.body.addEventListener("mousemove", function(e) { last_move_timestamp = Date.now(); cursor.style.left = e.clientX + "px", cursor.style.top = e.clientY + "px"; });
 * { padding: 0; margin: 0; border: 0; } html, body { width: 100%; height: 100%; min-height: 100%; background: #e8e8e8; cursor: none; } .inactive-fade-out { transition: opacity 150ms ease-out; } #cursor { position: fixed; border-radius: 50%; transform: translateX(-50%) translateY(-50%); left: -100px; top: 50%; background-color: black; height: 8px; width: 8px; transition: all 150ms ease-out; }
 <div id="cursor" class="inactive-fade-out"></div>

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!