Skip to content

Adding 'once' option for IntersectionObserverInit (feature request) #146

Open
@ziyunfei

Description

@ziyunfei

I have a real use case here: getting all IMG elements which at least 50% are displayed in the viewport at 2 seconds after the page is loaded.

setTimeout(() => {
  let observer = new IntersectionObserver(entries => {
    entries.forEach(entry => {
      console.log(entry.target)
    })
  }, {
    threshold: 0.5,
    // once: true
  })
  Array.from(document.querySelectorAll("img")).forEach(item => observer.observe(item))
  setTimeout(() => observer.disconnect(), 20) // a workaround.
}, 2000)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions