From 2d49c15863f080b21f577995500de7a391fc43ad Mon Sep 17 00:00:00 2001 From: Scott Newcomer Date: Sun, 18 Feb 2018 08:17:37 -0800 Subject: [PATCH] change intersection threshold default to 0 (#126) --- README.md | 14 ++++++++++---- addon/initializers/viewport-config.js | 2 +- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index a89d6500..e93081f9 100644 --- a/README.md +++ b/README.md @@ -84,7 +84,7 @@ export default Ember.Component.extend(InViewportMixin, { viewportUseIntersectionObserver : true, viewportScrollSensitivity : 1, viewportRefreshRate : 150, - intersectionThreshold : 1.0, + intersectionThreshold : 0, scrollableArea : null, viewportTolerance: { top : 50, @@ -112,13 +112,19 @@ export default Ember.Component.extend(InViewportMixin, { (https://developer.mozilla.org/en-US/docs/Web/API/Intersection_Observer_API) (https://developer.mozilla.org/en-US/docs/Web/API/IntersectionObserver/thresholds#Browser_compatibility) -- `intersectionThreshold: decimal` +- `intersectionThreshold: decimal or array` - Default: 1.0 + Default: 0 A single number or array of numbers between 0.0 and 1.0. A value of 0.0 means the target will be visible when the first pixel enters the viewport. A value of 1.0 means the entire target must be visible to fire the didEnterViewport hook. + Similarily, [0, .25, .5, .75, 1] will fire didEnterViewport every 25% of the target that is visible. (https://developer.mozilla.org/en-US/docs/Web/API/Intersection_Observer_API#Thresholds) + Some notes: + - If the target is offscreen, you will get a notification via `didExitViewport` that the target is initially offscreen. Similarily, this is possible to notify if onscreen when your site loads. + - If intersectionThreshold is set to anything greater than 0, you will not see `didExitViewport` hook fired due to our use of the `isIntersecting` property. See last comment here: https://bugs.chromium.org/p/chromium/issues/detail?id=713819 for purpose of `isIntersecting` + - If your intersectionThreshold is set to 0 you will get notified if the target `didEnterViewport` and `didExitViewport` at the appropriate time. + - `scrollableArea` Default: null @@ -173,7 +179,7 @@ module.exports = function(environment) { viewportScrollSensitivity : 1, viewportRefreshRate : 100, viewportListeners : [], - intersectionThreshold : 1.0, + intersectionThreshold : 0, scrollableArea : null, viewportTolerance: { top : 0, diff --git a/addon/initializers/viewport-config.js b/addon/initializers/viewport-config.js index 683d92dc..6feb920a 100644 --- a/addon/initializers/viewport-config.js +++ b/addon/initializers/viewport-config.js @@ -16,7 +16,7 @@ const defaultConfig = { bottom: 0, right: 0 }, - intersectionThreshold: 1.0, + intersectionThreshold: 0, scrollableArea: null // defaults to layout view (document.documentElement) };