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

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

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 Relatório

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