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

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