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

170
Views
How to delay el.classList.remove?

If you see an image when scrolling, it is set to be an animation. If I can't see the image, I'll let them return to their original state, but I'd like to give them a "five-second" delay, not "immediately." I tried to put delay, but it failed. Is there anyone who can help? This is an example.

window.onload = function () {
            const targets = document.querySelectorAll('[data-observer]')
            const images = document.querySelectorAll('[data-img]')
            const options = {
                rootMargin: '0px',
                threshold: 1.0
            }
            const addClass = (el) => {
                if (!el.classList.contains('is-visible')) {
                    el.classList.add('is-visible')
                }
            }
            const removeClass = (el) => {
                if (el.classList.contains('is-visible')) {
                    el.classList.remove('is-visible')
                }
            }




            const doThings = (entries, observer) => {
                entries.forEach(entry => {
                    if (entry.isIntersecting) {
                        addClass(entry.target)
                    } else {
                        removeClass(entry.target)
                    }
                })
            }
            const observer = new IntersectionObserver(doThings, options)
            const observer2 = new IntersectionObserver(doThings, {
                ... options,
                threshold: 0.4
            })
            targets.forEach(target => {
                observer.observe(target)
            })
            images.forEach(target => {
                observer2.observe(target)
            })
        }
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Bro,use Thread.sleep() for delay.

about 4 years ago · Juan Pablo Isaza Report

0

setTimeout

The global setTimeout() method sets a timer which executes a function or specified piece of code once the timer expires. (From MDN)

Usage

setTimeout(function, delay);

Better explained here.

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!