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

129
Visualizações
Using Intersection Observer to make a pull-to-refresh function in mobile PWA

I'm trying to implement a pull-to-refresh function in my mobile PWA.

Since I want to avoid using touchStart and touchEnd to determine if the user pulled down the page, so I thought about using an intersectionObserver.

My approach is "if page wrapper is 50% in view, fire refresh function".

( pullToRefresh = () => { 

  const wrapper = document.querySelector('.wrapper');

  const options = {
    root: null,
    rootMargin: "0px 0px 0px 0px",
    threshold: 0,
  };

  wrapperObserver = new IntersectionObserver (function (entries, observer) {
    entries.forEach(function(entry) {
      if (entry.intersectionRatio > 0.5) {
        console.log('wrapper in view')
      } else if (entry.intersectionRatio <= 0.5) {
        console.log("wrapper out of view")
        location.reload(true)
      }
    });
  }, options);

  wrapperObserver(wrapper);

})();

The const wrapper is in view from the beginning and always only 100vh high.

However, I can't get it to fire. (I'm using the iOS simulator to test it.) Thanks for any tips!

about 4 years ago · Santiago Gelvez
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