scroll-into-view
Advanced tools
Comparing version 1.12.3 to 1.13.1
{ | ||
"name": "scroll-into-view", | ||
"version": "1.12.3", | ||
"version": "1.13.1", | ||
"description": "scrolls an elements into view, recursively aligning parents.", | ||
@@ -18,8 +18,6 @@ "main": "scrollIntoView.js", | ||
"watchExample": "watchify ./example/index.js -d -o ./example/index.browser.js", | ||
"updateChangelog": "git log | chlogit > CHANGELOG.md && git add CHANGELOG.md", | ||
"prepublish": "npm run-script build" | ||
"prepublish": "npm run-script build", | ||
"serve": "static example", | ||
"start": "npm-run-all -p serve watchExample" | ||
}, | ||
"pre-commit": [ | ||
"updateChangelog" | ||
], | ||
"author": "", | ||
@@ -31,3 +29,4 @@ "license": "MIT", | ||
"crel": "^1.1.1", | ||
"pre-commit": "^1.2.2", | ||
"node-static": "^0.7.11", | ||
"npm-run-all": "^4.1.5", | ||
"tape": "~2.1.0", | ||
@@ -34,0 +33,0 @@ "tape-run": "^6.0.1", |
@@ -77,4 +77,5 @@ | ||
maxSynchronousAlignments: 3 // default is 3. Maximum number of times to try and align elements synchronously before completing. | ||
maxSynchronousAlignments: 3, // default is 3. Maximum number of times to try and align elements synchronously before completing. | ||
debug: true // default is false. This will spit out some logs that can help you understand what scroll-into-view is doing if it isn't doing what you expect. | ||
}); | ||
@@ -96,2 +97,6 @@ ``` | ||
## Changelog | ||
[View Changeog](https://changelogit.korynunn.com/#korynunn/scroll-into-view) | ||
## Testing | ||
@@ -98,0 +103,0 @@ |
@@ -126,2 +126,7 @@ var COMPLETE = 'complete', | ||
} | ||
if(settings.debug){ | ||
console.log('Scrolling ended with type', endType, 'for', parent) | ||
} | ||
callback(endType); | ||
@@ -208,2 +213,10 @@ if(cancelHandler){ | ||
if(settings.debug){ | ||
console.log('About to scroll to', target) | ||
if(!parent){ | ||
console.error('Target did not have a parent, is it mounted in the DOM?') | ||
} | ||
} | ||
while(parent){ | ||
@@ -214,3 +227,7 @@ if(parent.tagName === 'BODY'){ | ||
} | ||
if(settings.debug){ | ||
console.log('Scrolling parent node', parent) | ||
} | ||
if(validTarget(parent, parents) && (isScrollable ? isScrollable(parent, defaultIsScrollable) : defaultIsScrollable(parent))){ | ||
@@ -217,0 +234,0 @@ parents++; |
(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),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("BODY"===l.tagName&&(l=(l=l.ownerDocument).defaultView||l.ownerWindow),r(l,i)&&(a?a(l,defaultIsScrollable):defaultIsScrollable(l))&&(i++,transitionScrollTo(e,l,t,o)),!(l=l.parentElement)){o(COMPLETE);break}}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,o,r,a,s,c=e.align,f=e.target.getBoundingClientRect(),d=c&&null!=c.left?c.left:.5,u=c&&null!=c.top?c.top:.5,g=c&&null!=c.leftOffset?c.leftOffset:0,m=c&&null!=c.topOffset?c.topOffset:0,h=d,p=u;if(e.isWindow(t))a=Math.min(f.width,t.innerWidth),s=Math.min(f.height,t.innerHeight),l=f.left+t.pageXOffset-t.innerWidth*h+a*h,i=f.top+t.pageYOffset-t.innerHeight*p+s*p,i-=m,o=(l-=g)-t.pageXOffset,r=i-t.pageYOffset;else{a=f.width,s=f.height,n=t.getBoundingClientRect();var S=f.left-(n.left-t.scrollLeft),E=f.top-(n.top-t.scrollTop);l=S+a*h-t.clientWidth*h,i=E+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-=m,o=(l-=g)-t.scrollLeft,r=i-t.scrollTop}return{x:l,y:i,differenceX:o,differenceY:r}}function animate(e){var t=e._scrollSettings;if(t){var n=t.maxSynchronousAlignments,l=getTargetScrollLocation(t,e),i=Date.now()-t.startTime,o=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 r=1-t.ease(o);if(setElementScroll(e,l.x-l.differenceX*r,l.y-l.differenceY*r),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,o=!t._scrollSettings,r=t._scrollSettings,a=Date.now(),s={passive:!0};function c(e){t._scrollSettings=null,t.parentElement&&t.parentElement._scrollSettings&&t.parentElement._scrollSettings.end(e),n.debug&&console.log("Scrolling ended with type",e,"for",t),l(e),i&&(t.removeEventListener("touchstart",i,s),t.removeEventListener("wheel",i,s))}r&&r.end(CANCELED);var f=n.maxSynchronousAlignments;null==f&&(f=3),t._scrollSettings={startTime:r?r.startTime:Date.now(),endIterations:0,target:e,time:n.time+(r?a-r.startTime:0),ease:n.ease,align:n.align,isWindow:n.isWindow||defaultIsWindow,maxSynchronousAlignments:f,end:c},"cancellable"in n&&!n.cancellable||(i=c.bind(null,CANCELED),t.addEventListener("touchstart",i,s),t.addEventListener("wheel",i,s)),o&&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)};var l=e.parentElement,i=1,o=t.validTarget||defaultValidTarget,r=t.isScrollable;for(t.debug&&(console.log("About to scroll to",e),l||console.error("Target did not have a parent, is it mounted in the DOM?"));l;)if("BODY"===l.tagName&&(l=(l=l.ownerDocument).defaultView||l.ownerWindow),t.debug&&console.log("Scrolling parent node",l),o(l,i)&&(r?r(l,defaultIsScrollable):defaultIsScrollable(l))&&(i++,transitionScrollTo(e,l,t,a)),!(l=l.parentElement)){a(COMPLETE);break}}function a(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
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
219
151
19842
9
6