element-in-view
Version:
Check if an element is in viewport.
3 lines (2 loc) • 606 B
JavaScript
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):t.elementInView=e()}(this,function(){"use strict";return function(t,e){void 0===e&&(e={});var i=e.offset;void 0===i&&(i=0);var n=e.threshold;void 0===n&&(n=0);var o=t.getBoundingClientRect(),d=o.top,r=o.right,f=o.bottom,u=o.left,h=o.width,l=o.height,c={t:f,r:window.innerWidth-u,b:window.innerHeight-d,l:r},p={x:n*h,y:n*l};return c.t>=(i.top||i+p.y)&&c.r>=(i.right||i+p.x)&&c.b>=(i.bottom||i+p.y)&&c.l>=(i.left||i+p.x)}});
//# sourceMappingURL=element-in-view.min.js.map