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

225
Views
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 answers
Answer question

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 Report

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