@livelybone/scroll-get
Advanced tools
Comparing version 6.0.3 to 6.1.0
@@ -129,2 +129,9 @@ declare function getRect(el: Element): DOMRect | ||
): () => void | ||
/** | ||
* Judge whether the element is in current page view | ||
* */ | ||
declare function isElementInView( | ||
el?: HTMLElement | null, | ||
scroller?: HTMLElement | null, | ||
): boolean | ||
@@ -142,2 +149,3 @@ export { | ||
getViewElementsWhenScroll, | ||
isElementInView, | ||
posRelativeToClient, | ||
@@ -144,0 +152,0 @@ posRelativeToPage, |
/** | ||
* Bundle of @livelybone/scroll-get | ||
* Generated: 2021-05-27 | ||
* Version: 6.0.3 | ||
* Version: 6.1.0 | ||
* License: MIT | ||
@@ -373,3 +373,26 @@ * Author: 2631541504@qq.com | ||
} | ||
/** | ||
* Judge whether the element is in current page view | ||
* */ | ||
export { animation, getMaxScrollOffset, getNativeScrollbarWidth, getRect, getScrollParent, getViewElementsWhenScroll, posRelativeToClient, posRelativeToPage, scrollToElement }; | ||
function isElementInView(el, scroller) { | ||
if (!el || !scroller) return false; | ||
var rect = el.getBoundingClientRect(); | ||
var scrollerRect = scroller.getBoundingClientRect(); | ||
var windowRect = { | ||
x: 0, | ||
y: 0, | ||
width: window.innerWidth, | ||
height: window.innerHeight | ||
}; | ||
scrollerRect.x = Math.max(scrollerRect.x, windowRect.x); | ||
scrollerRect.y = Math.max(scrollerRect.y, windowRect.y); | ||
scrollerRect.width = Math.min(scrollerRect.width, windowRect.width); | ||
scrollerRect.height = Math.min(scrollerRect.height, windowRect.height); | ||
if (rect.x + rect.width <= scrollerRect.x) return false; | ||
if (rect.x >= scrollerRect.x + scrollerRect.width) return false; | ||
if (rect.y + rect.height < scrollerRect.y) return false; | ||
return rect.y < scrollerRect.y + scrollerRect.height; | ||
} | ||
export { animation, getMaxScrollOffset, getNativeScrollbarWidth, getRect, getScrollParent, getViewElementsWhenScroll, isElementInView, posRelativeToClient, posRelativeToPage, scrollToElement }; |
/** | ||
* Bundle of @livelybone/scroll-get | ||
* Generated: 2021-05-27 | ||
* Version: 6.0.3 | ||
* Version: 6.1.0 | ||
* License: MIT | ||
@@ -9,2 +9,2 @@ * Author: 2631541504@qq.com | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e=e||self).ScrollGet={})}(this,function(e){"use strict";function t(t,e){var n,r=Object.keys(t);return Object.getOwnPropertySymbols&&(n=Object.getOwnPropertySymbols(t),e&&(n=n.filter(function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable})),r.push.apply(r,n)),r}function d(r){for(var e=1;e<arguments.length;e++){var o=null!=arguments[e]?arguments[e]:{};e%2?t(Object(o),!0).forEach(function(e){var t,n;t=r,e=o[n=e],n in t?Object.defineProperty(t,n,{value:e,enumerable:!0,configurable:!0,writable:!0}):t[n]=e}):Object.getOwnPropertyDescriptors?Object.defineProperties(r,Object.getOwnPropertyDescriptors(o)):t(Object(o)).forEach(function(e){Object.defineProperty(r,e,Object.getOwnPropertyDescriptor(o,e))})}return r}function h(e,t){if(null==e)return{};var n,r=function(e,t){if(null==e)return{};for(var n,r={},o=Object.keys(e),i=0;i<o.length;i++)n=o[i],0<=t.indexOf(n)||(r[n]=e[n]);return r}(e,t);if(Object.getOwnPropertySymbols)for(var o=Object.getOwnPropertySymbols(e),i=0;i<o.length;i++)n=o[i],0<=t.indexOf(n)||Object.prototype.propertyIsEnumerable.call(e,n)&&(r[n]=e[n]);return r}function v(e){return e.getBoundingClientRect()}function n(e){return e+(1-e)*e}function w(r,o,e){function i(e){window.requestAnimationFrame(function(){e()&&i(e)})}var l=e||n;return new Promise(function(t){var n=Date.now();i(function(){var e=l(Math.min(1,(Date.now()-n)/r));return o(e),!(1<=e)||(t(),!1)})})}function m(e){var t=window.getComputedStyle(e),n={top:0,left:0};return"HTML"!==e.nodeName&&!["scroll","auto","overlay"].includes(t.overflowX)||(n.left=Math.max(0,e.scrollWidth-e.clientWidth)),"HTML"!==e.nodeName&&!["scroll","auto","overlay"].includes(t.overflowY)||(n.top=Math.max(0,e.scrollHeight-e.clientHeight)),n}function r(e){return!e.top&&!e.left}function b(e){if(null!=e&&e.style){var t=window.getComputedStyle(e);if("fixed"!==t.position){var n=e.ownerDocument;if("absolute"===t.position)return e.offsetParent?b(e.offsetParent):r(m(n.body))?b(n.body):n.body;e=e.parentElement;return e?r(m(e))&&e!==n.documentElement?b(e):e:void 0}}}e.animation=w,e.getMaxScrollOffset=m,e.getNativeScrollbarWidth=function(e){var t=e||window,n=t===window;try{var r,o,i=n?window.nativeScrollbarWidth:null;return i&&"number"==typeof i.y&&"number"==typeof i.x||(r=e&&"ownerDocument"in e?e.ownerDocument:document,o=n?r.createElement("div"):t,n&&(o.setAttribute("style","position:fixed;top:0;left:0;opacity:0;pointer-events:none;width:200px;height:200px;overflow:scroll"),r.body.appendChild(o)),i={y:o.offsetWidth-o.clientWidth,x:o.offsetHeight-o.clientHeight},n&&(window.nativeScrollbarWidth=i,r.body.removeChild(o))),i}catch(e){return{y:17,x:17}}},e.getRect=v,e.getScrollParent=b,e.getViewElementsWhenScroll=function(r,o,i){if(0<o.length){var l=[],e=function(e){var n=v(r),t=o.map(v).map(function(e,t){return e.viewHeight=Math.max(0,Math.min(e.top+e.height,n.top+n.height)-Math.max(n.top,e.top)),e.viewWidth=Math.max(0,Math.min(e.left+e.width,n.left+n.width)-Math.max(n.left,e.left)),e.height&&e.width?e.viewPercent=e.viewHeight*e.viewWidth/e.height*e.width:e.height||e.width?e.height?e.viewPercent=e.viewHeight/e.height:e.viewPercent=e.viewWidth/e.width:e.viewPercent=0,{rect:e,element:o[t]}}).filter(function(e){return 0<e.rect.viewPercent}).sort(function(e,t){var n=t.rect.viewPercent-e.rect.viewPercent;return n||t.rect.viewHeight*t.rect.viewWidth-e.rect.viewHeight*e.rect.viewWidth});t.length===l.length&&!t.some(function(e,t){return e.element!==l[t].element})||i(l=t,n,e)};return e(),r.addEventListener("scroll",e),function(){return r.removeEventListener("scroll",e)}}return function(){}},e.posRelativeToClient=function(e){return{clientLeft:(e=v(e)).left,clientTop:e.top}},e.posRelativeToPage=function(e){for(var t={pageLeft:0,pageTop:0},n=e;n;)t.pageLeft+=n.offsetLeft,t.pageTop+=n.offsetTop,n=n.offsetParent;return t},e.scrollToElement=function e(t,n){var r=n||{},o=r.offset,i=void 0===o?0:o,n=r.time,l=void 0===n?300:n,f=h(r,["offset","time"]),o="number"==typeof i?{left:i,top:i}:{left:i.left||0,top:i.top||0},c=b(t);if(c&&(!f.topDisabled||!f.leftDisabled)){var n=function(){return e(c,d({time:l},f))},r=m(c),a=c.scrollLeft,u=c.scrollTop,i=v(t),t=v(c);"HTML"===c.nodeName&&(t.y=0);var p=Math.min(i.left-t.left+o.left,r.left-c.scrollLeft),s=Math.min(i.top-t.top+o.top,r.top-c.scrollTop);if(p&&!f.leftDisabled||s&&!f.topDisabled)return w(l,function(e){f.topDisabled||(c.scrollTop=u+s*e),f.leftDisabled||(c.scrollLeft=a+p*e)},f.rateFactor).then(f.affectParent?n:null);if(f.affectParent)return n()}return Promise.resolve()},Object.defineProperty(e,"__esModule",{value:!0})}); | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e=e||self).ScrollGet={})}(this,function(e){"use strict";function t(t,e){var n,r=Object.keys(t);return Object.getOwnPropertySymbols&&(n=Object.getOwnPropertySymbols(t),e&&(n=n.filter(function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable})),r.push.apply(r,n)),r}function p(r){for(var e=1;e<arguments.length;e++){var i=null!=arguments[e]?arguments[e]:{};e%2?t(Object(i),!0).forEach(function(e){var t,n;t=r,e=i[n=e],n in t?Object.defineProperty(t,n,{value:e,enumerable:!0,configurable:!0,writable:!0}):t[n]=e}):Object.getOwnPropertyDescriptors?Object.defineProperties(r,Object.getOwnPropertyDescriptors(i)):t(Object(i)).forEach(function(e){Object.defineProperty(r,e,Object.getOwnPropertyDescriptor(i,e))})}return r}function s(e,t){if(null==e)return{};var n,r=function(e,t){if(null==e)return{};for(var n,r={},i=Object.keys(e),o=0;o<i.length;o++)n=i[o],0<=t.indexOf(n)||(r[n]=e[n]);return r}(e,t);if(Object.getOwnPropertySymbols)for(var i=Object.getOwnPropertySymbols(e),o=0;o<i.length;o++)n=i[o],0<=t.indexOf(n)||Object.prototype.propertyIsEnumerable.call(e,n)&&(r[n]=e[n]);return r}function w(e){return e.getBoundingClientRect()}function n(e){return e+(1-e)*e}function v(r,i,e){function o(e){window.requestAnimationFrame(function(){e()&&o(e)})}var l=e||n;return new Promise(function(t){var n=Date.now();o(function(){var e=l(Math.min(1,(Date.now()-n)/r));return i(e),!(1<=e)||(t(),!1)})})}function m(e){var t=window.getComputedStyle(e),n={top:0,left:0};return"HTML"!==e.nodeName&&!["scroll","auto","overlay"].includes(t.overflowX)||(n.left=Math.max(0,e.scrollWidth-e.clientWidth)),"HTML"!==e.nodeName&&!["scroll","auto","overlay"].includes(t.overflowY)||(n.top=Math.max(0,e.scrollHeight-e.clientHeight)),n}function r(e){return!e.top&&!e.left}function g(e){if(null!=e&&e.style){var t=window.getComputedStyle(e);if("fixed"!==t.position){var n=e.ownerDocument;if("absolute"===t.position)return e.offsetParent?g(e.offsetParent):r(m(n.body))?g(n.body):n.body;e=e.parentElement;return e?r(m(e))&&e!==n.documentElement?g(e):e:void 0}}}e.animation=v,e.getMaxScrollOffset=m,e.getNativeScrollbarWidth=function(e){var t=e||window,n=t===window;try{var r,i,o=n?window.nativeScrollbarWidth:null;return o&&"number"==typeof o.y&&"number"==typeof o.x||(r=e&&"ownerDocument"in e?e.ownerDocument:document,i=n?r.createElement("div"):t,n&&(i.setAttribute("style","position:fixed;top:0;left:0;opacity:0;pointer-events:none;width:200px;height:200px;overflow:scroll"),r.body.appendChild(i)),o={y:i.offsetWidth-i.clientWidth,x:i.offsetHeight-i.clientHeight},n&&(window.nativeScrollbarWidth=o,r.body.removeChild(i))),o}catch(e){return{y:17,x:17}}},e.getRect=w,e.getScrollParent=g,e.getViewElementsWhenScroll=function(r,i,o){if(0<i.length){var l=[],e=function(e){var n=w(r),t=i.map(w).map(function(e,t){return e.viewHeight=Math.max(0,Math.min(e.top+e.height,n.top+n.height)-Math.max(n.top,e.top)),e.viewWidth=Math.max(0,Math.min(e.left+e.width,n.left+n.width)-Math.max(n.left,e.left)),e.height&&e.width?e.viewPercent=e.viewHeight*e.viewWidth/e.height*e.width:e.height||e.width?e.height?e.viewPercent=e.viewHeight/e.height:e.viewPercent=e.viewWidth/e.width:e.viewPercent=0,{rect:e,element:i[t]}}).filter(function(e){return 0<e.rect.viewPercent}).sort(function(e,t){var n=t.rect.viewPercent-e.rect.viewPercent;return n||t.rect.viewHeight*t.rect.viewWidth-e.rect.viewHeight*e.rect.viewWidth});t.length===l.length&&!t.some(function(e,t){return e.element!==l[t].element})||o(l=t,n,e)};return e(),r.addEventListener("scroll",e),function(){return r.removeEventListener("scroll",e)}}return function(){}},e.isElementInView=function(e,t){if(!e||!t)return!1;var n=e.getBoundingClientRect(),e=t.getBoundingClientRect(),t={x:0,y:0,width:window.innerWidth,height:window.innerHeight};return e.x=Math.max(e.x,t.x),e.y=Math.max(e.y,t.y),e.width=Math.min(e.width,t.width),e.height=Math.min(e.height,t.height),!(n.x+n.width<=e.x)&&(!(n.x>=e.x+e.width)&&(!(n.y+n.height<e.y)&&n.y<e.y+e.height))},e.posRelativeToClient=function(e){return{clientLeft:(e=w(e)).left,clientTop:e.top}},e.posRelativeToPage=function(e){for(var t={pageLeft:0,pageTop:0},n=e;n;)t.pageLeft+=n.offsetLeft,t.pageTop+=n.offsetTop,n=n.offsetParent;return t},e.scrollToElement=function e(t,n){var r=n||{},i=r.offset,o=void 0===i?0:i,n=r.time,l=void 0===n?300:n,f=s(r,["offset","time"]),i="number"==typeof o?{left:o,top:o}:{left:o.left||0,top:o.top||0},c=g(t);if(c&&(!f.topDisabled||!f.leftDisabled)){var n=function(){return e(c,p({time:l},f))},r=m(c),a=c.scrollLeft,u=c.scrollTop,o=w(t),t=w(c);"HTML"===c.nodeName&&(t.y=0);var h=Math.min(o.left-t.left+i.left,r.left-c.scrollLeft),d=Math.min(o.top-t.top+i.top,r.top-c.scrollTop);if(h&&!f.leftDisabled||d&&!f.topDisabled)return v(l,function(e){f.topDisabled||(c.scrollTop=u+d*e),f.leftDisabled||(c.scrollLeft=a+h*e)},f.rateFactor).then(f.affectParent?n:null);if(f.affectParent)return n()}return Promise.resolve()},Object.defineProperty(e,"__esModule",{value:!0})}); |
{ | ||
"name": "@livelybone/scroll-get", | ||
"version": "6.0.3", | ||
"version": "6.1.0", | ||
"description": "Some useful tool of browser scroll, such as tool for calculating position relative to page/client, tool for getting the native scrollbar width...", | ||
@@ -5,0 +5,0 @@ "main": "./lib/umd/index.js", |
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
30334
509