scroll-into-view
Advanced tools
Comparing version 1.11.0 to 1.12.0
{ | ||
"name": "scroll-into-view", | ||
"version": "1.11.0", | ||
"version": "1.12.0", | ||
"description": "", | ||
@@ -35,2 +35,5 @@ "main": "scrollIntoView.js", | ||
}, | ||
"files": [ | ||
"*.js" | ||
], | ||
"dependencies": {}, | ||
@@ -37,0 +40,0 @@ "collective": { |
@@ -73,4 +73,6 @@ ![scroll-into-view](/scrollintoview.png) ![example-gif](/scrollIntoViewExample.gif) | ||
cancellable: true // default is true, set to false to prevent users from cancelling the scroll with a touch or mousewheel | ||
cancellable: true, // default is true, set to false to prevent users from cancelling the scroll with a touch or mousewheel | ||
maxSynchronousAlignments: 3 // default is 3. Maximum number of times to try and align elements synchronously before completing. | ||
}); | ||
@@ -77,0 +79,0 @@ ``` |
@@ -74,2 +74,3 @@ var COMPLETE = 'complete', | ||
var scrollSettings = parent._scrollSettings; | ||
if(!scrollSettings){ | ||
@@ -79,2 +80,4 @@ return; | ||
var maxSynchronousAlignments = scrollSettings.maxSynchronousAlignments; | ||
var location = getTargetScrollLocation(scrollSettings, parent), | ||
@@ -84,6 +87,3 @@ time = Date.now() - scrollSettings.startTime, | ||
if( | ||
time > scrollSettings.time && | ||
scrollSettings.endIterations > 3 | ||
){ | ||
if(scrollSettings.endIterations >= maxSynchronousAlignments){ | ||
setElementScroll(parent, location.x, location.y); | ||
@@ -94,4 +94,2 @@ parent._scrollSettings = null; | ||
scrollSettings.endIterations++; | ||
var easeValue = 1 - scrollSettings.ease(timeValue); | ||
@@ -104,5 +102,4 @@ | ||
// At the end of animation, loop synchronously | ||
// to try and hit the taget location. | ||
if(time >= scrollSettings.time){ | ||
scrollSettings.endIterations++; | ||
return animate(parent); | ||
@@ -141,2 +138,8 @@ } | ||
var maxSynchronousAlignments = settings.maxSynchronousAlignments; | ||
if(maxSynchronousAlignments == null){ | ||
maxSynchronousAlignments = 3; | ||
} | ||
parent._scrollSettings = { | ||
@@ -150,2 +153,3 @@ startTime: lastSettings ? lastSettings.startTime : Date.now(), | ||
isWindow: settings.isWindow || defaultIsWindow, | ||
maxSynchronousAlignments: maxSynchronousAlignments, | ||
end: end | ||
@@ -198,3 +202,3 @@ }; | ||
var parent = target.parentElement, | ||
parents = 0; | ||
parents = 1; | ||
@@ -220,5 +224,3 @@ function done(endType){ | ||
if(!parent){ | ||
if(!parents){ | ||
callback && callback(COMPLETE) | ||
} | ||
done(COMPLETE) | ||
break; | ||
@@ -225,0 +227,0 @@ } |
(function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i<t.length;i++)o(t[i]);return o}return r})()({1:[function(require,module,exports){ | ||
var COMPLETE="complete",CANCELED="canceled";function raf(e){if("requestAnimationFrame"in window)return window.requestAnimationFrame(e);setTimeout(e,16)}function setElementScroll(e,t,n){e.self===e?e.scrollTo(t,n):(e.scrollLeft=t,e.scrollTop=n)}function getTargetScrollLocation(e,t){var n,l,i,r,a,o,s,f=e.align,c=e.target.getBoundingClientRect(),d=f&&null!=f.left?f.left:.5,u=f&&null!=f.top?f.top:.5,m=f&&null!=f.leftOffset?f.leftOffset:0,g=f&&null!=f.topOffset?f.topOffset:0,h=d,p=u;if(e.isWindow(t))o=Math.min(c.width,t.innerWidth),s=Math.min(c.height,t.innerHeight),l=c.left+t.pageXOffset-t.innerWidth*h+o*h,i=c.top+t.pageYOffset-t.innerHeight*p+s*p,i-=g,r=(l-=m)-t.pageXOffset,a=i-t.pageYOffset;else{o=c.width,s=c.height,n=t.getBoundingClientRect();var E=c.left-(n.left-t.scrollLeft),w=c.top-(n.top-t.scrollTop);l=E+o*h-t.clientWidth*h,i=w+s*p-t.clientHeight*p,l=Math.max(Math.min(l,t.scrollWidth-t.clientWidth),0),i=Math.max(Math.min(i,t.scrollHeight-t.clientHeight),0),i-=g,r=(l-=m)-t.scrollLeft,a=i-t.scrollTop}return{x:l,y:i,differenceX:r,differenceY:a}}function animate(e){var t=e._scrollSettings;if(t){var n=getTargetScrollLocation(t,e),l=Date.now()-t.startTime,i=Math.min(1/t.time*l,1);if(l>t.time&&t.endIterations>3)return setElementScroll(e,n.x,n.y),e._scrollSettings=null,t.end(COMPLETE);t.endIterations++;var r=1-t.ease(i);if(setElementScroll(e,n.x-n.differenceX*r,n.y-n.differenceY*r),l>=t.time)return animate(e);raf(animate.bind(null,e))}}function defaultIsWindow(e){return e.self===e}function transitionScrollTo(e,t,n,l){var i,r=!t._scrollSettings,a=t._scrollSettings,o=Date.now(),s={passive:!0};function f(e){t._scrollSettings=null,t.parentElement&&t.parentElement._scrollSettings&&t.parentElement._scrollSettings.end(e),l(e),i&&(t.removeEventListener("touchstart",i,s),t.removeEventListener("wheel",i,s))}a&&a.end(CANCELED),t._scrollSettings={startTime:a?a.startTime:Date.now(),endIterations:0,target:e,time:n.time+(a?o-a.startTime:0),ease:n.ease,align:n.align,isWindow:n.isWindow||defaultIsWindow,end:f},"cancellable"in n&&!n.cancellable||(i=f.bind(null,CANCELED),t.addEventListener("touchstart",i,s),t.addEventListener("wheel",i,s)),r&&animate(t)}function defaultIsScrollable(e){return"pageXOffset"in e||(e.scrollHeight!==e.clientHeight||e.scrollWidth!==e.clientWidth)&&"hidden"!==getComputedStyle(e).overflow}function defaultValidTarget(){return!0}module.exports=function(e,t,n){if(e){"function"==typeof t&&(n=t,t=null),t||(t={}),t.time=isNaN(t.time)?1e3:t.time,t.ease=t.ease||function(e){return 1-Math.pow(1-e,e/2)};for(var l=e.parentElement,i=0,r=t.validTarget||defaultValidTarget,a=t.isScrollable;l;){if(r(l,i)&&(a?a(l,defaultIsScrollable):defaultIsScrollable(l))&&(i++,transitionScrollTo(e,l,t,o)),!(l=l.parentElement)){i||n&&n(COMPLETE);break}"BODY"===l.tagName&&(l=(l=l.ownerDocument).defaultView||l.ownerWindow)}}function o(e){--i||n&&n(e)}}; | ||
var COMPLETE="complete",CANCELED="canceled";function raf(e){if("requestAnimationFrame"in window)return window.requestAnimationFrame(e);setTimeout(e,16)}function setElementScroll(e,t,n){e.self===e?e.scrollTo(t,n):(e.scrollLeft=t,e.scrollTop=n)}function getTargetScrollLocation(e,t){var n,l,i,r,a,o,s,f=e.align,c=e.target.getBoundingClientRect(),d=f&&null!=f.left?f.left:.5,u=f&&null!=f.top?f.top:.5,m=f&&null!=f.leftOffset?f.leftOffset:0,g=f&&null!=f.topOffset?f.topOffset:0,h=d,p=u;if(e.isWindow(t))o=Math.min(c.width,t.innerWidth),s=Math.min(c.height,t.innerHeight),l=c.left+t.pageXOffset-t.innerWidth*h+o*h,i=c.top+t.pageYOffset-t.innerHeight*p+s*p,i-=g,r=(l-=m)-t.pageXOffset,a=i-t.pageYOffset;else{o=c.width,s=c.height,n=t.getBoundingClientRect();var E=c.left-(n.left-t.scrollLeft),S=c.top-(n.top-t.scrollTop);l=E+o*h-t.clientWidth*h,i=S+s*p-t.clientHeight*p,l=Math.max(Math.min(l,t.scrollWidth-t.clientWidth),0),i=Math.max(Math.min(i,t.scrollHeight-t.clientHeight),0),i-=g,r=(l-=m)-t.scrollLeft,a=i-t.scrollTop}return{x:l,y:i,differenceX:r,differenceY:a}}function animate(e){var t=e._scrollSettings;if(t){var n=t.maxSynchronousAlignments,l=getTargetScrollLocation(t,e),i=Date.now()-t.startTime,r=Math.min(1/t.time*i,1);if(t.endIterations>=n)return setElementScroll(e,l.x,l.y),e._scrollSettings=null,t.end(COMPLETE);var a=1-t.ease(r);if(setElementScroll(e,l.x-l.differenceX*a,l.y-l.differenceY*a),i>=t.time)return t.endIterations++,animate(e);raf(animate.bind(null,e))}}function defaultIsWindow(e){return e.self===e}function transitionScrollTo(e,t,n,l){var i,r=!t._scrollSettings,a=t._scrollSettings,o=Date.now(),s={passive:!0};function f(e){t._scrollSettings=null,t.parentElement&&t.parentElement._scrollSettings&&t.parentElement._scrollSettings.end(e),l(e),i&&(t.removeEventListener("touchstart",i,s),t.removeEventListener("wheel",i,s))}a&&a.end(CANCELED);var c=n.maxSynchronousAlignments;null==c&&(c=3),t._scrollSettings={startTime:a?a.startTime:Date.now(),endIterations:0,target:e,time:n.time+(a?o-a.startTime:0),ease:n.ease,align:n.align,isWindow:n.isWindow||defaultIsWindow,maxSynchronousAlignments:c,end:f},"cancellable"in n&&!n.cancellable||(i=f.bind(null,CANCELED),t.addEventListener("touchstart",i,s),t.addEventListener("wheel",i,s)),r&&animate(t)}function defaultIsScrollable(e){return"pageXOffset"in e||(e.scrollHeight!==e.clientHeight||e.scrollWidth!==e.clientWidth)&&"hidden"!==getComputedStyle(e).overflow}function defaultValidTarget(){return!0}module.exports=function(e,t,n){if(e){"function"==typeof t&&(n=t,t=null),t||(t={}),t.time=isNaN(t.time)?1e3:t.time,t.ease=t.ease||function(e){return 1-Math.pow(1-e,e/2)};for(var l=e.parentElement,i=1,r=t.validTarget||defaultValidTarget,a=t.isScrollable;l;){if(r(l,i)&&(a?a(l,defaultIsScrollable):defaultIsScrollable(l))&&(i++,transitionScrollTo(e,l,t,o)),!(l=l.parentElement)){o(COMPLETE);break}"BODY"===l.tagName&&(l=(l=l.ownerDocument).defaultView||l.ownerWindow)}}function o(e){--i||n&&n(e)}}; | ||
@@ -4,0 +4,0 @@ },{}],2:[function(require,module,exports){ |
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
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
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 2 instances in 1 package
144
2
26719
7
206
1