intersection-events
Advanced tools
Comparing version 0.2.0 to 0.2.1
/*! | ||
* intersection-events v0.2.0 | ||
* intersection-events v0.2.1 | ||
* https://github.com/ko-yelie/intersection-events#readme | ||
@@ -18,2 +18,3 @@ * | ||
var THRESHOLD_RATIO = 0.02; | ||
/** | ||
@@ -40,2 +41,3 @@ * Wrapper of IntersectionObserver | ||
var thresholdRatio = Math.abs(enterThreshold - leaveThreshold) * THRESHOLD_RATIO; | ||
var isEnter; | ||
@@ -49,5 +51,13 @@ var isLeave; | ||
} else { | ||
isEnter = function (entry) { return Math.abs(entry.intersectionRatio - enterThreshold) <= Math.abs(entry.intersectionRatio - leaveThreshold); }; | ||
isEnter = function (entry) { | ||
var enterRatio = Math.abs(entry.intersectionRatio - enterThreshold); | ||
var leaveRatio = Math.abs(entry.intersectionRatio - leaveThreshold); | ||
return enterRatio <= leaveRatio && enterRatio < thresholdRatio; | ||
}; | ||
isLeave = function (entry) { return Math.abs(entry.intersectionRatio - enterThreshold) >= Math.abs(entry.intersectionRatio - leaveThreshold); }; | ||
isLeave = function (entry) { | ||
var enterRatio = Math.abs(entry.intersectionRatio - enterThreshold); | ||
var leaveRatio = Math.abs(entry.intersectionRatio - leaveThreshold); | ||
return enterRatio >= leaveRatio && leaveRatio < thresholdRatio; | ||
}; | ||
} | ||
@@ -54,0 +64,0 @@ |
/*! | ||
* intersection-events v0.2.0 | ||
* intersection-events v0.2.1 | ||
* https://github.com/ko-yelie/intersection-events#readme | ||
@@ -43,2 +43,3 @@ * | ||
var THRESHOLD_RATIO = 0.02; | ||
/** | ||
@@ -65,2 +66,3 @@ * Wrapper of IntersectionObserver | ||
var thresholdRatio = Math.abs(enterThreshold - leaveThreshold) * THRESHOLD_RATIO; | ||
var isEnter; | ||
@@ -74,5 +76,13 @@ var isLeave; | ||
} else { | ||
isEnter = function (entry) { return Math.abs(entry.intersectionRatio - enterThreshold) <= Math.abs(entry.intersectionRatio - leaveThreshold); }; | ||
isEnter = function (entry) { | ||
var enterRatio = Math.abs(entry.intersectionRatio - enterThreshold); | ||
var leaveRatio = Math.abs(entry.intersectionRatio - leaveThreshold); | ||
return enterRatio <= leaveRatio && enterRatio < thresholdRatio; | ||
}; | ||
isLeave = function (entry) { return Math.abs(entry.intersectionRatio - enterThreshold) >= Math.abs(entry.intersectionRatio - leaveThreshold); }; | ||
isLeave = function (entry) { | ||
var enterRatio = Math.abs(entry.intersectionRatio - enterThreshold); | ||
var leaveRatio = Math.abs(entry.intersectionRatio - leaveThreshold); | ||
return enterRatio >= leaveRatio && leaveRatio < thresholdRatio; | ||
}; | ||
} | ||
@@ -79,0 +89,0 @@ |
/*! | ||
* intersection-events v0.2.0 | ||
* intersection-events v0.2.1 | ||
* https://github.com/ko-yelie/intersection-events#readme | ||
@@ -12,2 +12,2 @@ * | ||
*/ | ||
var IntersectionEvents=function(){"use strict";function e(){}return function(n,t){void 0===t&&(t={});var r=t.onEnter,i=t.onLeave;void 0===i&&(i=e);var o=t.isOnce;void 0===o&&(o=!1);var s=t.enterThreshold;void 0===s&&(s=.99);var c,v,a=t.leaveThreshold;void 0===a&&(a=0),1===s&&(s=.99),1===a&&(a=.99),s===a?(c=function(e){return e.isIntersecting},v=function(e){return 0===a?!e.isIntersecting:e.isIntersecting}):(c=function(e){return Math.abs(e.intersectionRatio-s)<=Math.abs(e.intersectionRatio-a)},v=function(e){return Math.abs(e.intersectionRatio-s)>=Math.abs(e.intersectionRatio-a)});var u,E=function(e){e.forEach(function(e){var n=e.target;!n.intersectionEvents.isEnter&&c(e)?(n.intersectionEvents.isEnter=!0,r(n),o&&n.intersectionEvents.observer.unobserve(n)):n.intersectionEvents.isEnter&&v(e)&&(n.intersectionEvents.isEnter=!1,i(n))})},h=new IntersectionObserver(E,{threshold:[a,s]});(u=n,u?("string"==typeof u&&(u=document.querySelectorAll(u)),"length"in u&&u.nodeType!==Node.ELEMENT_NODE&&!function(e){return e.location&&e.document&&e.alert&&e.setInterval}(u)?Array.apply(null,u):[u]):[]).forEach(function(e){e.intersectionEvents={},e.intersectionEvents.isEnter=!1;var n=window.innerHeight/e.offsetHeight,t=s>n,r=a>n;e.intersectionEvents.observer=h,(t||r)&&(e.intersectionEvents.observer=new IntersectionObserver(E,{threshold:[r?a*n:a,t?s*n:s]})),e.intersectionEvents.observer.observe(e)})}}(); | ||
var IntersectionEvents=function(){"use strict";function e(){}return function(n,t){void 0===t&&(t={});var r=t.onEnter,i=t.onLeave;void 0===i&&(i=e);var s=t.isOnce;void 0===s&&(s=!1);var o=t.enterThreshold;void 0===o&&(o=.99);var c=t.leaveThreshold;void 0===c&&(c=0),1===o&&(o=.99),1===c&&(c=.99);var v,a,u=.02*Math.abs(o-c);o===c?(v=function(e){return e.isIntersecting},a=function(e){return 0===c?!e.isIntersecting:e.isIntersecting}):(v=function(e){var n=Math.abs(e.intersectionRatio-o);return n<=Math.abs(e.intersectionRatio-c)&&n<u},a=function(e){var n=Math.abs(e.intersectionRatio-o),t=Math.abs(e.intersectionRatio-c);return n>=t&&t<u});var E,h=function(e){e.forEach(function(e){var n=e.target;!n.intersectionEvents.isEnter&&v(e)?(n.intersectionEvents.isEnter=!0,r(n),s&&n.intersectionEvents.observer.unobserve(n)):n.intersectionEvents.isEnter&&a(e)&&(n.intersectionEvents.isEnter=!1,i(n))})},f=new IntersectionObserver(h,{threshold:[c,o]});(E=n,E?("string"==typeof E&&(E=document.querySelectorAll(E)),"length"in E&&E.nodeType!==Node.ELEMENT_NODE&&!function(e){return e.location&&e.document&&e.alert&&e.setInterval}(E)?Array.apply(null,E):[E]):[]).forEach(function(e){e.intersectionEvents={},e.intersectionEvents.isEnter=!1;var n=window.innerHeight/e.offsetHeight,t=o>n,r=c>n;e.intersectionEvents.observer=f,(t||r)&&(e.intersectionEvents.observer=new IntersectionObserver(h,{threshold:[r?c*n:c,t?o*n:o]})),e.intersectionEvents.observer.observe(e)})}}(); |
{ | ||
"name": "intersection-events", | ||
"moduleName": "IntersectionEvents", | ||
"version": "0.2.0", | ||
"version": "0.2.1", | ||
"description": "Wrapper of IntersectionObserver", | ||
@@ -6,0 +6,0 @@ "main": "dist/intersection-events.es.js", |
# intersection-events | ||
Wrapper of [IntersectionObserver](https://developer.mozilla.org/en-US/docs/Web/API/IntersectionObserver) | ||
Wrapper of [`IntersectionObserver`](https://developer.mozilla.org/en-US/docs/Web/API/IntersectionObserver) | ||
@@ -31,2 +31,13 @@ You can detect when **the whole element enters and leaves** window. | ||
If you want to detect enter only once, set `isOnce` option to `true`. | ||
```js | ||
new IntersectionEvents('.js-target', { | ||
onEnter: el => { | ||
// Do only once | ||
}, | ||
isOnce: true | ||
}) | ||
``` | ||
## CDN | ||
@@ -48,3 +59,3 @@ | ||
**If you should support browsers that do not support IntersectionObserver, use [IntersectionObserver polyfill](https://github.com/w3c/IntersectionObserver/tree/master/polyfill).** | ||
**If you should support browsers that do not support `IntersectionObserver`, use [`IntersectionObserver` polyfill](https://github.com/w3c/IntersectionObserver/tree/master/polyfill).** | ||
@@ -51,0 +62,0 @@ --- |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
12785
216
65