intersection-observer
Advanced tools
Comparing version 0.5.0 to 0.5.1
@@ -36,3 +36,3 @@ /** | ||
* An IntersectionObserver registry. This registry exists to hold a strong | ||
* reference to IntersectionObserver instances currently observering a target | ||
* reference to IntersectionObserver instances currently observing a target | ||
* element. Without this registry, instances without another reference may be | ||
@@ -66,3 +66,5 @@ * garbage collected. | ||
if (targetArea) { | ||
this.intersectionRatio = intersectionArea / targetArea; | ||
// Round the intersection ratio to avoid floating point math issues: | ||
// https://github.com/w3c/IntersectionObserver/issues/324 | ||
this.intersectionRatio = Number((intersectionArea / targetArea).toFixed(4)); | ||
} else { | ||
@@ -255,3 +257,3 @@ // If area is zero and is intersecting, sets to 1, otherwise to 0 | ||
* Starts polling for intersection changes if the polling is not already | ||
* happening, and if the page's visibilty state is visible. | ||
* happening, and if the page's visibility state is visible. | ||
* @private | ||
@@ -558,3 +560,3 @@ */ | ||
/** | ||
* Throttles a function and delays its executiong, so it's only called at most | ||
* Throttles a function and delays its execution, so it's only called at most | ||
* once within a given time period. | ||
@@ -690,3 +692,3 @@ * @param {Function} fn The function to throttle. | ||
/** | ||
* Checks to see if a parent element contains a child elemnt (including inside | ||
* Checks to see if a parent element contains a child element (including inside | ||
* shadow DOM). | ||
@@ -693,0 +695,0 @@ * @param {Node} parent The parent element. |
{ | ||
"name": "intersection-observer", | ||
"version": "0.5.0", | ||
"version": "0.5.1", | ||
"description": "A polyfill for IntersectionObserver", | ||
@@ -5,0 +5,0 @@ "main": "intersection-observer", |
@@ -84,2 +84,16 @@ # `IntersectionObserver` polyfill | ||
**Ignoring DOM changes** | ||
You can also choose to not check for intersections when the DOM changes by setting an observer's `USE_MUTATION_OBSERVER` property to `false` (either globally on the prototype or per-instance) | ||
```js | ||
IntersectionObserver.prototype.USE_MUTATION_OBSERVER = false; // Globally | ||
// for an instance | ||
var io = new IntersectionObserver(callback); | ||
io.USE_MUTATION_OBSERVER = false; | ||
``` | ||
This is recommended in cases where the DOM will update frequently but you know those updates will have no affect on the position or your target elements. | ||
## Browser support | ||
@@ -86,0 +100,0 @@ |
71541
11
1541
148