From ab83c1e419b25436e76ed94f06e056f0bb1f4d53 Mon Sep 17 00:00:00 2001 From: Lukas Eipert Date: Mon, 26 Nov 2018 14:26:23 +0100 Subject: [PATCH] Use intersectionRatio to determine intersection Some older browsers do not ship with isIntersecting, while they already have IntersectionObserver support. We make use of `intersectionRatio` now to fix the Lazy Loader for those browsers. --- app/assets/javascripts/lazy_loader.js | 4 +++- .../unreleased/54407-fix-limited-intersection-observers.yml | 5 +++++ 2 files changed, 8 insertions(+), 1 deletion(-) create mode 100644 changelogs/unreleased/54407-fix-limited-intersection-observers.yml diff --git a/app/assets/javascripts/lazy_loader.js b/app/assets/javascripts/lazy_loader.js index af50ea9d6c2..ee01a73a6e8 100644 --- a/app/assets/javascripts/lazy_loader.js +++ b/app/assets/javascripts/lazy_loader.js @@ -91,7 +91,9 @@ export default class LazyLoader { onIntersection = entries => { entries.forEach(entry => { - if (entry.isIntersecting) { + // We are using `intersectionRatio > 0` over `isIntersecting`, as some browsers did not ship the latter + // See: https://gitlab.com/gitlab-org/gitlab-ce/issues/54407 + if (entry.intersectionRatio > 0) { this.intersectionObserver.unobserve(entry.target); this.lazyImages.push(entry.target); } diff --git a/changelogs/unreleased/54407-fix-limited-intersection-observers.yml b/changelogs/unreleased/54407-fix-limited-intersection-observers.yml new file mode 100644 index 00000000000..2c2bedb170b --- /dev/null +++ b/changelogs/unreleased/54407-fix-limited-intersection-observers.yml @@ -0,0 +1,5 @@ +--- +title: Fix Image Lazy Loader for some older browsers +merge_request: +author: +type: fixed