Vanilla-lazyload: Occasionally, IntersectionObserver reports a 0 IntersectionRatio, stopping a reveal

Created on 9 Jan 2018  路  6Comments  路  Source: verlok/vanilla-lazyload

  • What is happening?

Certain horizontal rows never load their images because IntersectionObserver occasionally reports an IntersectionRatio of 0. In my local dist I've moved to >= for the check on L195, but maybe that should be removed altogether? I'm not seeing over-firing of events or prematurely-loaded images as-is.

  • What is the expected behaviour?

The row loads on intersection

  • Which version of LazyLoad are you using?

10.4.x

  • In which browser(s) and browser version(s) are you experiencing the problem?

Chromium 64

  • Could you provide the HTML, CSS and JS code you use for your images?

I can't share the source, but I'm using something nearly identical to the basic example in the README.

  • What are the steps to reproduce the problem?
  1. Have multiple rows of images.
  2. Set a breakpoint at https://github.com/verlok/lazyload/blob/master/dist/lazyload.js#L195
  3. Occasionally IntersectionObserver reports all entries have an IntersectionRatio of 0, and won't fire another intersection event for these items unless you scroll back up
  4. Be frustrated
  • Thank you

Thank you for the very well-maintained lib!

Bug

Most helpful comment

Thanks so much!!

All 6 comments

Unfortunately, modifying the ratio check means that all images are loaded immediately on the initialization of the IntersectionObserver instance -- I'm still trying to figure out how to get it to not activate initially.

This is gross and probably not ideal, but I got it working by adding state to the constructor so that the first time the IntsectionObserver calls onIntersection (when it ends up called for all target entries) it breaks:

https://gist.github.com/broguinn/b77e3d89456894ef7a719ef3bcbb47f1

One more update: to get entries to load their images that are initially visible on page load, I changed the check line to:
if (entry.intersectionRatio > 0 || _this._initialized) {

Hi @broguinn,
thanks for submitting the issue and for the analysis. I鈥檒l check everything and fix it as soon as possible.

Released 10.4.2 which fixes this.

Thanks so much!!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Cyriltra picture Cyriltra  路  4Comments

briwg picture briwg  路  8Comments

sendmenas picture sendmenas  路  6Comments

starfishpatkhoo picture starfishpatkhoo  路  6Comments

isuke01 picture isuke01  路  3Comments