Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

scrolldir

Package Overview
Dependencies
Maintainers
2
Versions
32
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

scrolldir - npm Package Compare versions

Comparing version 1.2.9 to 1.2.13

CODEOWNERS

133

dist/scrolldir.auto.js
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory() :
typeof define === 'function' && define.amd ? define(factory) :
(factory());
typeof exports === 'object' && typeof module !== 'undefined' ? factory() :
typeof define === 'function' && define.amd ? define(factory) :
(factory());
}(this, (function () { 'use strict';
function scrollDir() {
var el = document.documentElement;
var win = window;
var attribute = 'data-scrolldir';
var body = document.body;
var historyLength = 32; // Ticks to keep in history.
var historyMaxAge = 512; // History data time-to-live (ms).
var thresholdPixels = 64; // Ignore moves smaller than this.
var history = Array(historyLength);
var dir = 'down'; // 'up' or 'down'
var e = void 0; // last scroll event
var pivot = void 0; // "high-water mark"
var pivotTime = 0;
var defaults = {
el: document.documentElement,
win: window,
attribute: 'data-scrolldir'
};
var el = void 0;
var win = void 0;
var attribute = void 0;
var body = document.body;
var historyLength = 32; // Ticks to keep in history.
var historyMaxAge = 512; // History data time-to-live (ms).
var thresholdPixels = 64; // Ignore moves smaller than this.
var history = Array(historyLength);
var dir = 'down'; // 'up' or 'down'
var e = void 0; // last scroll event
var pivot = void 0; // "high-water mark"
var pivotTime = 0;
var tick = function tickFunc() {
var y = win.scrollY;
var t = e.timeStamp;
var furthest = dir === 'down' ? Math.max : Math.min;
function tick() {
var y = win.scrollY || win.pageYOffset;
var t = e.timeStamp;
var furthest = dir === 'down' ? Math.max : Math.min;
// Apply bounds to handle rubber banding
var yMax = body.offsetHeight - win.innerHeight;
y = Math.max(0, y);
y = Math.min(yMax, y);
// Apply bounds to handle rubber banding
var yMax = body.offsetHeight - win.innerHeight;
y = Math.max(0, y);
y = Math.min(yMax, y);
// Update history
history.unshift({ y: y, t: t });
history.pop();
// Update history
history.unshift({ y: y, t: t });
history.pop();
// Are we continuing in the same direction?
if (y === furthest(pivot, y)) {
// Update "high-water mark" for current direction
pivotTime = t;
pivot = y;
return;
}
// else we have backed off high-water mark
// Are we continuing in the same direction?
if (y === furthest(pivot, y)) {
// Update "high-water mark" for current direction
pivotTime = t;
pivot = y;
return;
}
// else we have backed off high-water mark
// Apply max age to find current reference point
var cutoffTime = t - historyMaxAge;
if (cutoffTime > pivotTime) {
pivot = y;
for (var i = 0; i < historyLength; i += 1) {
if (!history[i] || history[i].t < cutoffTime) break;
pivot = furthest(pivot, history[i].y);
}
// Apply max age to find current reference point
var cutoffTime = t - historyMaxAge;
if (cutoffTime > pivotTime) {
pivot = y;
for (var i = 0; i < historyLength; i += 1) {
if (!history[i] || history[i].t < cutoffTime) break;
pivot = furthest(pivot, history[i].y);
}
}
// Have we exceeded threshold?
if (Math.abs(y - pivot) > thresholdPixels) {
pivot = y;
pivotTime = t;
dir = dir === 'down' ? 'up' : 'down';
el.setAttribute(attribute, dir);
}
};
// Have we exceeded threshold?
if (Math.abs(y - pivot) > thresholdPixels) {
pivot = y;
pivotTime = t;
dir = dir === 'down' ? 'up' : 'down';
el.setAttribute(attribute, dir);
}
}
var handler = function handlerFunc(event) {
e = event;
win.requestAnimationFrame(tick);
};
function handler(event) {
e = event;
return win.requestAnimationFrame(tick);
}
pivot = win.scrollY;
function scrollDir(opts) {
el = opts && opts.el || defaults.el;
win = opts && opts.win || defaults.win;
attribute = opts && opts.attribute || defaults.attribute;
// If opts.off, turn it off
// - set html[data-scrolldir="off"]
// - remove the event listener
if (opts && opts.off === true) {
el.setAttribute(attribute, 'off');
return win.removeEventListener('scroll', handler);
}
// else, turn it on
// - set html[data-scrolldir="down"]
// - add the event listener
pivot = win.scrollY || win.pageYOffset;
el.setAttribute(attribute, dir);
return win.addEventListener('scroll', handler);
}
scrollDir();
})));
/**
* scrolldir - Vertical scroll direction in CSS
* @version v1.2.8
* @version v1.2.13
* @link https://github.com/dollarshaveclub/scrolldir.git

@@ -8,2 +8,2 @@ * @author Patrick Fisher <patrick@pwfisher.com>

**/
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e():"function"==typeof define&&define.amd?define(e):e()}(0,function(){"use strict";!function(){var t=document.documentElement,e=window,n=document.body,o=Array(32),i="down",d=void 0,r=void 0,a=0,f=function(){var f=e.scrollY,u=d.timeStamp,c="down"===i?Math.max:Math.min,s=n.offsetHeight-e.innerHeight;if(f=Math.max(0,f),f=Math.min(s,f),o.unshift({y:f,t:u}),o.pop(),f===c(r,f))return a=u,void(r=f);var m=u-512;if(m>a){r=f;for(var l=0;l<32&&o[l]&&!(o[l].t<m);l+=1)r=c(r,o[l].y)}Math.abs(f-r)>64&&(r=f,a=u,i="down"===i?"up":"down",t.setAttribute("data-scrolldir",i))},u=function(t){d=t,e.requestAnimationFrame(f)};r=e.scrollY,t.setAttribute("data-scrolldir",i),e.addEventListener("scroll",u)}()});
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e():"function"==typeof define&&define.amd?define(e):e()}(0,function(){"use strict";function t(){var t=o.scrollY||o.pageYOffset,e=l.timeStamp,n="down"===c?Math.max:Math.min,p=f.offsetHeight-o.innerHeight;if(t=Math.max(0,t),t=Math.min(p,t),s.unshift({y:t,t:e}),s.pop(),t===n(m,t))return v=e,void(m=t);var b=e-a;if(b>v){m=t;for(var w=0;w<d&&(s[w]&&!(s[w].t<b));w+=1)m=n(m,s[w].y)}Math.abs(t-m)>u&&(m=t,v=e,c="down"===c?"up":"down",i.setAttribute(r,c))}function e(e){return l=e,o.requestAnimationFrame(t)}var n={el:document.documentElement,win:window,attribute:"data-scrolldir"},i=void 0,o=void 0,r=void 0,f=document.body,d=32,a=512,u=64,s=Array(d),c="down",l=void 0,m=void 0,v=0;!function(t){i=t&&t.el||n.el,o=t&&t.win||n.win,r=t&&t.attribute||n.attribute,t&&!0===t.off?(i.setAttribute(r,"off"),o.removeEventListener("scroll",e)):(m=o.scrollY||o.pageYOffset,i.setAttribute(r,c),o.addEventListener("scroll",e))}()});
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
typeof define === 'function' && define.amd ? define(factory) :
(global.scrollDir = factory());
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
typeof define === 'function' && define.amd ? define(factory) :
(global.scrollDir = factory());
}(this, (function () { 'use strict';

@@ -26,3 +26,3 @@

function tick() {
var y = win.scrollY;
var y = win.scrollY || win.pageYOffset;
var t = e.timeStamp;

@@ -89,3 +89,3 @@ var furthest = dir === 'down' ? Math.max : Math.min;

// - add the event listener
pivot = win.scrollY;
pivot = win.scrollY || win.pageYOffset;
el.setAttribute(attribute, dir);

@@ -92,0 +92,0 @@ return win.addEventListener('scroll', handler);

/**
* scrolldir - Vertical scroll direction in CSS
* @version v1.2.8
* @version v1.2.13
* @link https://github.com/dollarshaveclub/scrolldir.git

@@ -8,2 +8,2 @@ * @author Patrick Fisher <patrick@pwfisher.com>

**/
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):t.scrollDir=e()}(this,function(){"use strict";function t(){var t=r.scrollY,e=m.timeStamp,n="down"===c?Math.max:Math.min,i=u.offsetHeight-r.innerHeight;if(t=Math.max(0,t),t=Math.min(i,t),l.unshift({y:t,t:e}),l.pop(),t===n(v,t))return b=e,void(v=t);var h=e-f;if(h>b){v=t;for(var p=0;p<a&&(l[p]&&!(l[p].t<h));p+=1)v=n(v,l[p].y)}Math.abs(t-v)>s&&(v=t,b=e,c="down"===c?"up":"down",o.setAttribute(d,c))}function e(e){return m=e,r.requestAnimationFrame(t)}function n(t){return o=t&&t.el||i.el,r=t&&t.win||i.win,d=t&&t.attribute||i.attribute,t&&!0===t.off?(o.setAttribute(d,"off"),r.removeEventListener("scroll",e)):(v=r.scrollY,o.setAttribute(d,c),r.addEventListener("scroll",e))}var i={el:document.documentElement,win:window,attribute:"data-scrolldir"},o=void 0,r=void 0,d=void 0,u=document.body,a=32,f=512,s=64,l=Array(a),c="down",m=void 0,v=void 0,b=0;return n});
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):t.scrollDir=e()}(this,function(){"use strict";function t(){var t=o.scrollY||o.pageYOffset,e=c.timeStamp,n="down"===l?Math.max:Math.min,p=d.offsetHeight-o.innerHeight;if(t=Math.max(0,t),t=Math.min(p,t),s.unshift({y:t,t:e}),s.pop(),t===n(m,t))return v=e,void(m=t);var b=e-u;if(b>v){m=t;for(var h=0;h<f&&(s[h]&&!(s[h].t<b));h+=1)m=n(m,s[h].y)}Math.abs(t-m)>a&&(m=t,v=e,l="down"===l?"up":"down",i.setAttribute(r,l))}function e(e){return c=e,o.requestAnimationFrame(t)}var n={el:document.documentElement,win:window,attribute:"data-scrolldir"},i=void 0,o=void 0,r=void 0,d=document.body,f=32,u=512,a=64,s=Array(f),l="down",c=void 0,m=void 0,v=0;return function(t){return i=t&&t.el||n.el,o=t&&t.win||n.win,r=t&&t.attribute||n.attribute,t&&!0===t.off?(i.setAttribute(r,"off"),o.removeEventListener("scroll",e)):(m=o.scrollY||o.pageYOffset,i.setAttribute(r,l),o.addEventListener("scroll",e))}});
{
"name": "scrolldir",
"version": "1.2.9",
"version": "1.2.13",
"description": "Vertical scroll direction in CSS",

@@ -31,7 +31,7 @@ "main": "dist/scrolldir.min.js",

"devDependencies": {
"babel-preset-es2015-rollup": "^1.2.0",
"babel-preset-es2015-rollup": "^3.0.0",
"bower": "^1.7.9",
"eslint": "^3.9.1",
"eslint-config-airbnb": "^15.0.0",
"eslint-plugin-import": "^2.1.0",
"eslint": "^4.1.0",
"eslint-config-airbnb": "^15.0.1",
"eslint-plugin-import": "^2.3.0",
"gulp": "^3.9.1",

@@ -42,6 +42,6 @@ "gulp-header": "^1.8.8",

"node-qunit-phantomjs": "^1.4.0",
"rollup": "^0.36.3",
"rollup-plugin-babel": "^2.6.1",
"rollup-plugin-commonjs": "^5.0.5",
"rollup-plugin-eslint": "^3.0.0",
"rollup": "^0.45.2",
"rollup-plugin-babel": "^3.0.0",
"rollup-plugin-commonjs": "^8.0.2",
"rollup-plugin-eslint": "^4.0.0",
"rollup-plugin-node-resolve": "^3.0.0",

@@ -48,0 +48,0 @@ "rollup-plugin-uglify": "^2.0.0"

@@ -1,66 +0,3 @@

function scrollDir() {
const el = document.documentElement;
const win = window;
const attribute = 'data-scrolldir';
const body = document.body;
const historyLength = 32; // Ticks to keep in history.
const historyMaxAge = 512; // History data time-to-live (ms).
const thresholdPixels = 64; // Ignore moves smaller than this.
const history = Array(historyLength);
let dir = 'down'; // 'up' or 'down'
let e; // last scroll event
let pivot; // "high-water mark"
let pivotTime = 0;
import scrollDir from './scrolldir';
const tick = function tickFunc() {
let y = win.scrollY;
const t = e.timeStamp;
const furthest = dir === 'down' ? Math.max : Math.min;
// Apply bounds to handle rubber banding
const yMax = body.offsetHeight - win.innerHeight;
y = Math.max(0, y);
y = Math.min(yMax, y);
// Update history
history.unshift({ y, t });
history.pop();
// Are we continuing in the same direction?
if (y === furthest(pivot, y)) {
// Update "high-water mark" for current direction
pivotTime = t;
pivot = y;
return;
}
// else we have backed off high-water mark
// Apply max age to find current reference point
const cutoffTime = t - historyMaxAge;
if (cutoffTime > pivotTime) {
pivot = y;
for (let i = 0; i < historyLength; i += 1) {
if (!history[i] || history[i].t < cutoffTime) break;
pivot = furthest(pivot, history[i].y);
}
}
// Have we exceeded threshold?
if (Math.abs(y - pivot) > thresholdPixels) {
pivot = y;
pivotTime = t;
dir = dir === 'down' ? 'up' : 'down';
el.setAttribute(attribute, dir);
}
};
const handler = function handlerFunc(event) {
e = event;
win.requestAnimationFrame(tick);
};
pivot = win.scrollY;
el.setAttribute(attribute, dir);
return win.addEventListener('scroll', handler);
}
scrollDir();

@@ -20,3 +20,3 @@ const defaults = {

function tick() {
let y = win.scrollY;
let y = win.scrollY || win.pageYOffset;
const t = e.timeStamp;

@@ -83,5 +83,5 @@ const furthest = dir === 'down' ? Math.max : Math.min;

// - add the event listener
pivot = win.scrollY;
pivot = win.scrollY || win.pageYOffset;
el.setAttribute(attribute, dir);
return win.addEventListener('scroll', handler);
}

Sorry, the diff of this file is not supported yet

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