Socket
Socket
Sign inDemoInstall

scroll-into-view

Package Overview
Dependencies
Maintainers
1
Versions
50
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

scroll-into-view - npm Package Compare versions

Comparing version 1.9.7 to 1.10.0

5

CHANGELOG.md
## 1.9.7 - Tue May 7 2019
Removed opencollective postinstall - [8b63c9ad](korynunn@8b63c9adb6de93dde7157ef0bd7e2f205873fb43)
## 1.9.6 - Fri Apr 19 2019

@@ -3,0 +8,0 @@

16

example/index.browser.js

@@ -235,4 +235,6 @@ (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){

function getTargetScrollLocation(target, parent, align){
var targetPosition = target.getBoundingClientRect(),
function getTargetScrollLocation(scrollSettings, parent){
var align = scrollSettings.align,
target = scrollSettings.target,
targetPosition = target.getBoundingClientRect(),
parentPosition,

@@ -252,3 +254,3 @@ x,

if(parent.self === parent){
if(scrollSettings.isWindow(parent)){
targetWidth = Math.min(targetPosition.width, parent.innerWidth);

@@ -292,3 +294,3 @@ targetHeight = Math.min(targetPosition.height, parent.innerHeight);

var location = getTargetScrollLocation(scrollSettings.target, parent, scrollSettings.align),
var location = getTargetScrollLocation(scrollSettings, parent),
time = Date.now() - scrollSettings.startTime,

@@ -323,2 +325,7 @@ timeValue = Math.min(1 / scrollSettings.time * time, 1);

}
function defaultIsWindow(target){
return target.self === target
}
function transitionScrollTo(target, parent, settings, callback){

@@ -351,2 +358,3 @@ var idle = !parent._scrollSettings,

align: settings.align,
isWindow: settings.isWindow || defaultIsWindow,
end: end

@@ -353,0 +361,0 @@ };

{
"name": "scroll-into-view",
"version": "1.9.7",
"version": "1.10.0",
"description": "",

@@ -5,0 +5,0 @@ "main": "scrollIntoView.js",

![scroll-into-view](/scrollintoview.png) ![example-gif](/scrollIntoViewExample.gif)
[![Backers on Open Collective](https://opencollective.com/scroll-into-view/backers/badge.svg)](#backers)
[![Sponsors on Open Collective](https://opencollective.com/scroll-into-view/sponsors/badge.svg)](#sponsors)
[![Sponsors on Open Collective](https://opencollective.com/scroll-into-view/sponsors/badge.svg)](#sponsors)
## What

@@ -66,2 +66,7 @@

return defaultIsScrollable(target) || ~target.className.indexOf('scrollable');
},
isWindow: function(target){
// If you need special detection of the window object for some reason, you can do it here.
return target.self === target;
}

@@ -109,3 +114,3 @@

This project exists thanks to all the people who contribute.
This project exists thanks to all the people who contribute.
<a href="https://github.com/KoryNunn/scroll-into-view/graphs/contributors"><img src="https://opencollective.com/scroll-into-view/contributors.svg?width=890&button=false" /></a>

@@ -112,0 +117,0 @@

@@ -21,4 +21,6 @@ var COMPLETE = 'complete',

function getTargetScrollLocation(target, parent, align){
var targetPosition = target.getBoundingClientRect(),
function getTargetScrollLocation(scrollSettings, parent){
var align = scrollSettings.align,
target = scrollSettings.target,
targetPosition = target.getBoundingClientRect(),
parentPosition,

@@ -38,3 +40,3 @@ x,

if(parent.self === parent){
if(scrollSettings.isWindow(parent)){
targetWidth = Math.min(targetPosition.width, parent.innerWidth);

@@ -78,3 +80,3 @@ targetHeight = Math.min(targetPosition.height, parent.innerHeight);

var location = getTargetScrollLocation(scrollSettings.target, parent, scrollSettings.align),
var location = getTargetScrollLocation(scrollSettings, parent),
time = Date.now() - scrollSettings.startTime,

@@ -109,2 +111,7 @@ timeValue = Math.min(1 / scrollSettings.time * time, 1);

}
function defaultIsWindow(target){
return target.self === target
}
function transitionScrollTo(target, parent, settings, callback){

@@ -137,2 +144,3 @@ var idle = !parent._scrollSettings,

align: settings.align,
isWindow: settings.isWindow || defaultIsWindow,
end: end

@@ -139,0 +147,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,n){var l,i,r,a,o,s,f,c=e.getBoundingClientRect(),d=n&&null!=n.left?n.left:.5,u=n&&null!=n.top?n.top:.5,m=n&&null!=n.leftOffset?n.leftOffset:0,g=n&&null!=n.topOffset?n.topOffset:0,h=d,p=u;if(t.self===t)s=Math.min(c.width,t.innerWidth),f=Math.min(c.height,t.innerHeight),i=c.left+t.pageXOffset-t.innerWidth*h+s*h,r=c.top+t.pageYOffset-t.innerHeight*p+f*p,r-=g,a=(i-=m)-t.pageXOffset,o=r-t.pageYOffset;else{s=c.width,f=c.height,l=t.getBoundingClientRect();var E=c.left-(l.left-t.scrollLeft),v=c.top-(l.top-t.scrollTop);i=E+s*h-t.clientWidth*h,r=v+f*p-t.clientHeight*p,i=Math.max(Math.min(i,t.scrollWidth-t.clientWidth),0),r=Math.max(Math.min(r,t.scrollHeight-t.clientHeight),0),r-=g,a=(i-=m)-t.scrollLeft,o=r-t.scrollTop}return{x:i,y:r,differenceX:a,differenceY:o}}function animate(e){var t=e._scrollSettings;if(t){var n=getTargetScrollLocation(t.target,e,t.align),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 transitionScrollTo(e,t,n,l){var i,r=!t._scrollSettings,a=t._scrollSettings,o=Date.now();function s(e){t._scrollSettings=null,t.parentElement&&t.parentElement._scrollSettings&&t.parentElement._scrollSettings.end(e),l(e),t.removeEventListener("touchstart",i,{passive:!0}),t.removeEventListener("wheel",i,{passive:!0})}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,end:s},i=s.bind(null,CANCELED),t.addEventListener("touchstart",i,{passive:!0}),t.addEventListener("wheel",i,{passive:!0}),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,i,l,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),i=c.left+t.pageXOffset-t.innerWidth*h+o*h,l=c.top+t.pageYOffset-t.innerHeight*p+s*p,l-=g,r=(i-=m)-t.pageXOffset,a=l-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);i=E+o*h-t.clientWidth*h,l=w+s*p-t.clientHeight*p,i=Math.max(Math.min(i,t.scrollWidth-t.clientWidth),0),l=Math.max(Math.min(l,t.scrollHeight-t.clientHeight),0),l-=g,r=(i-=m)-t.scrollLeft,a=l-t.scrollTop}return{x:i,y:l,differenceX:r,differenceY:a}}function animate(e){var t=e._scrollSettings;if(t){var n=getTargetScrollLocation(t,e),i=Date.now()-t.startTime,l=Math.min(1/t.time*i,1);if(i>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(l);if(setElementScroll(e,n.x-n.differenceX*r,n.y-n.differenceY*r),i>=t.time)return animate(e);raf(animate.bind(null,e))}}function defaultIsWindow(e){return e.self===e}function transitionScrollTo(e,t,n,i){var l,r=!t._scrollSettings,a=t._scrollSettings,o=Date.now();function s(e){t._scrollSettings=null,t.parentElement&&t.parentElement._scrollSettings&&t.parentElement._scrollSettings.end(e),i(e),t.removeEventListener("touchstart",l,{passive:!0}),t.removeEventListener("wheel",l,{passive:!0})}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:s},l=s.bind(null,CANCELED),t.addEventListener("touchstart",l,{passive:!0}),t.addEventListener("wheel",l,{passive:!0}),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 i=e.parentElement,l=0,r=t.validTarget||defaultValidTarget,a=t.isScrollable;i;){if(r(i,l)&&(a?a(i,defaultIsScrollable):defaultIsScrollable(i))&&(l++,transitionScrollTo(e,i,t,o)),!(i=i.parentElement)){l||n&&n(COMPLETE);break}"BODY"===i.tagName&&(i=(i=i.ownerDocument).defaultView||i.ownerWindow)}}function o(e){--l||n&&n(e)}};

@@ -4,0 +4,0 @@ },{}],2:[function(require,module,exports){

@@ -328,2 +328,32 @@ var test = require('tape'),

});
});
test('custom isWindow', function(t) {
var target;
t.plan(2);
queue(function(next){
window.totallyWindow = true;
crel(document.body,
crel('div', {'style':'height:5000px;'},
target = crel('span', {'style':'position:absolute; top:2500px;'})
)
);
scrollIntoView(target, {
isWindow: function(target){
return target.totallyWindow;
}
}, function(type){
t.ok(
target.getBoundingClientRect().top < window.innerHeight,
'target was in view'
);
t.equal(type, 'complete');
next();
});
});
});

Sorry, the diff of this file is too big to display

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc