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 replace items when using intersection observer

Pretty new to code so forgive me if I stumble around some wording here, but I'm trying to use IntersectObserver to show a specific image when its corresponding text is shown in a scroll menu. Right now the appropriate images appear when the text is shown in the scroll menu, however, they appear in a flexbox column type manner and I would like them to replace each other once the text is no longer intersecting with the scroll menu. Are there any ideas how I might be able to do this?

const observer = new IntersectionObserver(entries => {
  entries.forEach(elem => {
    if (elem.isIntersecting) {
      const append = $(elem.target).append()
      const text = $(elem.target).text()

      
      switch (append, text) {
        case 'ALEX':
          $('.image-content').append("<img class='img' src='images/ALEX.gif'/>")
          break
        case 'CHANEL':
          $('.image-content').append("<img class='img' src='images/CHANEL.gif'/>")
          break
        case 'LAURA':
          $('.image-content').append("<img class='img' src='images/LAURA.gif'/>")
          break
        case 'NATHAN':
          $('.image-content').append("<img class='img' src='images/NATHAN.gif'/>")
          break
        case 'RON':
          $('.image-content').append("<img class='img' src='images/RON.gif'/>")
          break
        case 'STACEY':
          $('.image-content').append("<img class='img' src='images/STACEY.gif'/>")
          break
        case 'VINCE':
          $('.image-content').append("<img class='img' src='images/VINCE.gif'/>")
          break
        default:
          $('.image-content').text(`Sorry, no more companions available ${text}.`)
      }
    }
  })
})

// Select all the options in the left
$('.companion-names').each(function () {
  // For each item we want to observe whether it is visible using the function above
  observer.observe(this)
})
about 4 years ago · Juan Pablo Isaza
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!