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

228
Vistas
How to make text/div appear when the user stops scrolling

I'm trying to achieve an effect where the javascript detects whether the user has stopped scrolling/hovering over the page, and slowly shows a piece of text over the page, sort of like a paywall. The effect I'm trying to achieve is a simplified version of this website where when the user is inactive for a certain amount of time, eyes start to appear on the page

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

0

You can use setTimeout and clearTimeout to perform an action when the mouse stops moving. Here the text would reappear after 3 seconds of inactivity

var timeout;
var element = document.getElementById("element");

document.addEventListener("mousemove", function(e) {
  element.style.opacity = 0;
  clearTimeout(timeout);
  timeout = setTimeout(function() {
    element.style.opacity = 1;
  }, 2000);
});
#element {
  transition: opacity 0.5s;
  opacity 0;
}
<div id="element">I see you<div>

about 4 years ago · Juan Pablo Isaza Denunciar

0

First, you want to define what it means for a user to be "inactive". For example, we can consider a user to be inactive if they haven't moved their mouse or scrolled for 30 seconds. When that happens, we want to fire off some other code to signal that the user has gone inactive.

const addUserInactiveListener = (
  onUserInactive, 
  inactiveTimeMs = 30000
) => {
  let timeout = setTimeout(onUserInactive, inactiveTimeMs);

  const onUserAction = () => {
    clearTimeout(timeout);
    timeout = setTimeout(onUserInactive, inactiveTimeMs);
  }

  
  document.addEventListener('mousemove', onUserAction);
  document.addEventListener('scroll', onUserAction);
}

// console log after 5s of inactivity
addUserInactiveListener(() => console.log('inactive'), 5000)
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