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

scrollfeatures

Package Overview
Dependencies
Maintainers
1
Versions
18
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

scrollfeatures - npm Package Compare versions

Comparing version 1.0.2 to 1.1.0

dist/has-overflow.js

8

dist/scroll-parent.js
'use strict';
var regex = /(auto|scroll)/;
var hasOverflow = require('./has-overflow');

@@ -15,10 +15,8 @@ var scrollParent = function scrollParent(element) {

}
var style = window.getComputedStyle(element.parentNode, null);
if (regex.test(style.getPropertyValue('overflow') + style.getPropertyValue('overflow-y') + style.getPropertyValue('overflow-x'))) {
if (hasOverflow(element.parentNode)) {
return element.parentNode;
}
element = element.parentNode;
}
return window;

@@ -25,0 +23,0 @@ };

@@ -156,9 +156,10 @@ 'use strict';

this._canScrollY = this.clientHeight < this.scrollHeight;
this._canScrollX = this.clientWidth < this.scrollWidth;
if (this._scrollTarget !== window) {
var style = window.getComputedStyle(this._scrollTarget);
this._canScrollY = style['overflow-y'] !== 'hidden';
this._canScrollX = style['overflow-x'] !== 'hidden';
var regex = /(auto|scroll)/;
var style = window.getComputedStyle(this._scrollTarget, null);
this._canScrollY = regex.test(style.getPropertyValue('overflow-y'));
this._canScrollX = regex.test(style.getPropertyValue('overflow-x'));
} else {
this._canScrollY = this.clientHeight < this.scrollHeight;
this._canScrollX = this.clientWidth < this.scrollWidth;
}

@@ -194,2 +195,3 @@

this.onNextFrame = null;
delete this._scrollTarget.scrollFeatures;
this._scrollTarget = null;

@@ -251,3 +253,2 @@ this._destroyed = true;

// this._lastSpeed = this.speedY;
this._speedY = this._scrollY - this.scrollY;

@@ -254,0 +255,0 @@ this._speedX = this._scrollX - this.scrollX;

@@ -1,1 +0,1 @@

!function(t){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=t();else if("function"==typeof define&&define.amd)define([],t);else{var e;e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this,e.ScrollFeatures=t()}}(function(){return function t(e,i,n){function r(s,l){if(!i[s]){if(!e[s]){var c="function"==typeof require&&require;if(!l&&c)return c(s,!0);if(o)return o(s,!0);var a=new Error("Cannot find module '"+s+"'");throw a.code="MODULE_NOT_FOUND",a}var u=i[s]={exports:{}};e[s][0].call(u.exports,function(t){var i=e[s][1][t];return r(i?i:t)},u,u.exports,t,e,i,n)}return i[s].exports}for(var o="function"==typeof require&&require,s=0;s<n.length;s++)r(n[s]);return r}({1:[function(t,e){var i=function(t,e){var i=arguments.length<=2?[]:[].slice.call(arguments,2);return function(){return e.apply(t,arguments.length?i.slice().concat([].slice.call(arguments)):i)}};e.exports=i},{}],2:[function(t,e,i){"use strict";function n(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function r(t){for(var e in t)if(t.hasOwnProperty(e))return!1;return!0}Object.defineProperty(i,"__esModule",{value:!0});var o=function(){function t(){var e=arguments.length<=0||void 0===arguments[0]?{}:arguments[0],i=e.target,r=e.currentTarget;n(this,t),this._eventMap={},this._destroyed=!1,this._target=i||this,this._currentTarget=r||this,this.on=this.bind=this.addEventListener=this.addListener,this.off=this.unbind=this.removeEventListener=this.removeListener,this.once=this.one=this.addListenerOnce,this.emit=this.trigger=this.dispatchEvent=this.dispatch}return t.prototype.addListener=function(t,e){var i=this.getListener(t);return i?-1===i.indexOf(e)&&i.push(e):this._eventMap[t]=[e],this},t.prototype.addListenerOnce=function(t,e){var i=this,n=function(r){e(r),i.off(t,n),e=null,n=null};return this.on(t,n)},t.prototype.removeListener=function(t,e){if(!e)return this.removeAllListener(t);var i=this.getListener(t);if(i){var n=i.indexOf(e);n>-1&&(i=i.splice(n,1),i.length||delete this._eventMap[t])}return this},t.prototype.removeAllListener=function(t){var e=this.getListener(t);return e&&(this._eventMap[t].length=0,delete this._eventMap[t]),this},t.prototype.hasListener=function(t){return null!==this.getListener(t)},t.prototype.hasListeners=function(){return null!==this._eventMap&&void 0!==this._eventMap&&!r(this._eventMap)},t.prototype.dispatch=function(t,e){var i=this.getListener(t);if(i){e=e||{},e.type=t,e.target=e.target||this._target,e.currentTarget=e.currentTarget||this._currentTarget;for(var n=-1;++n<i.length;)i[n](e)}return this},t.prototype.getListener=function(t){var e=this._eventMap?this._eventMap[t]:null;return e||null},t.prototype.destroy=function(){if(this._eventMap){for(var t in this._eventMap)this.removeAllListener(t);this._eventMap=null}return this._destroyed=!0,this},t}();i["default"]=o,e.exports=i["default"]},{}],3:[function(t,e){"use strict";var i=/(auto|scroll)/,n=function(t){if(!(t instanceof HTMLElement))return window;for(;t.parentNode;){if(t.parentNode===document.body)return window;var e=window.getComputedStyle(t.parentNode,null);if(i.test(e.getPropertyValue("overflow")+e.getPropertyValue("overflow-y")+e.getPropertyValue("overflow-x")))return t.parentNode;t=t.parentNode}return window};e.exports=n},{}],4:[function(t,e,i){"use strict";function n(t){return t&&t.__esModule?t:{"default":t}}function r(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function o(t,e){if(!t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!e||"object"!=typeof e&&"function"!=typeof e?t:e}function s(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function, not "+typeof e);t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,enumerable:!1,writable:!0,configurable:!0}}),e&&(Object.setPrototypeOf?Object.setPrototypeOf(t,e):t.__proto__=e)}Object.defineProperty(i,"__esModule",{value:!0});var l=function w(t,e,i){null===t&&(t=Function.prototype);var n=Object.getOwnPropertyDescriptor(t,e);if(void 0===n){var r=Object.getPrototypeOf(t);return null===r?void 0:w(r,e,i)}if("value"in n)return n.value;var o=n.get;return void 0===o?void 0:o.call(i)},c=function(){function t(t,e){for(var i=0;i<e.length;i++){var n=e[i];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,n.key,n)}}return function(e,i,n){return i&&t(e.prototype,i),n&&t(e,n),e}}(),a=t("delegatejs"),u=n(a),h=t("eventdispatcher"),d=n(h),f=t("./scroll-parent"),g=n(f),_=function(t){function e(){var t=arguments.length<=0||void 0===arguments[0]?window:arguments[0],i=arguments.length<=1||void 0===arguments[1]?{}:arguments[1];if(r(this,e),e.hasInstance(t)){var n;return n=e.getInstance(t),o(s,n)}var s=o(this,(e.__proto__||Object.getPrototypeOf(e)).call(this,{target:t}));return t.scrollFeatures=s,s._scrollTarget=t,s.options=i,m.animationFrame&&e.unprefixAnimationFrame(),s.init(),s}return s(e,t),c(e,null,[{key:"getInstance",value:function(t,i){return t.scrollFeatures?t.scrollFeatures:new e(t,i)}},{key:"hasInstance",value:function(t){return"undefined"!=typeof t.scrollFeatures}},{key:"getScrollParent",value:function(t){return g["default"](t)}},{key:"unprefixAnimationFrame",value:function(){window.requestAnimationFrame||(window.requestAnimationFrame=window.requestAnimationFrame||window.mozRequestAnimationFrame||window.webkitRequestAnimationFrame||window.msRequestAnimationFrame,window.cancelAnimationFrame=window.cancelAnimationFrame||window.mozCancelAnimationFrame||window.webkitCancelAnimationFrame||window.msCancelAnimationFrame)}},{key:"directionToString",value:function(t){switch(t){case e.UP:return"up";case e.DOWN:return"down";case e.NONE:return"none";case e.LEFT:return"left";case e.RIGHT:return"right"}}},{key:"windowScrollY",get:function(){return window.pageYOffset||window.scrollY||0}},{key:"windowScrollX",get:function(){return window.pageXOffset||window.scrollX||0}},{key:"documentHeight",get:function(){return Math.max(document.body.scrollHeight,document.body.offsetHeight,document.documentElement.clientHeight,document.documentElement.scrollHeight,document.documentElement.offsetHeight)}},{key:"documentWidth",get:function(){return Math.max(document.body.scrollWidth,document.body.offsetWidth,document.documentElement.clientWidth,document.documentElement.scrollWidth,document.documentElement.offsetWidth)}}]),c(e,[{key:"init",value:function(){var t=this;if(this._destroyed=!1,this._scrollY=0,this._scrollX=0,this._speedY=0,this._speedX=0,this._lastSpeed=0,this._lastDirectionY=e.NONE,this._lastDirectionX=e.NONE,this._stopFrames=3,this._currentStopFrames=0,this._firstRender=!0,this._directionY=e.NONE,this._directionX=e.NONE,this._scrolling=!1,this._canScrollY=!1,this._canScrollX=!1,this.getScrollPosition=u["default"](this,this._scrollTarget===window?this._getWindowScrollPosition:this._getElementScrollPosition),this.onResize=u["default"](this,function(){return t.trigger(e.EVENT_SCROLL_RESIZE)}),this.onScroll=u["default"](this,this.onScroll),this.onNextFrame=u["default"](this,this.onNextFrame),this.updateScrollPosition(),this._canScrollY=this.clientHeight<this.scrollHeight,this._canScrollX=this.clientWidth<this.scrollWidth,this._scrollTarget!==window){var i=window.getComputedStyle(this._scrollTarget);this._canScrollY="hidden"!==i["overflow-y"],this._canScrollX="hidden"!==i["overflow-x"]}this._scrollTarget.addEventListener?(this._scrollTarget.addEventListener("scroll",this.onScroll,!1),this._scrollTarget.addEventListener("resize",this.onResize,!1)):this._scrollTarget.attachEvent&&(this._scrollTarget.attachEvent("scroll",this.onScroll),this._scrollTarget.attachEvent("resize",this.onResize))}},{key:"destroy",value:function(){this._destroyed||(this._cancelNextFrame(),l(e.prototype.__proto__||Object.getPrototypeOf(e.prototype),"destroy",this).call(this),this._scrollTarget.addEventListener?(this._scrollTarget.removeEventListener("scroll",this.onScroll),this._scrollTarget.removeEventListener("resize",this.onResize)):this._scrollTarget.attachEvent&&(this._scrollTarget.detachEvent("scroll",this.onScroll),this._scrollTarget.detachEvent("resize",this.onResize)),this.onResize=null,this.onScroll=null,this.getScrollPosition=null,this.onNextFrame=null,this._scrollTarget=null,this._destroyed=!0)}},{key:"updateScrollPosition",value:function(){this._scrollY=this.scrollY,this._scrollX=this.scrollX}},{key:"_getWindowScrollPosition",value:function(){return{y:e.windowScrollY,x:e.windowScrollX}}},{key:"_getElementScrollPosition",value:function(){return{y:this._scrollTarget.scrollTop,x:this._scrollTarget.scrollLeft}}},{key:"onScroll",value:function(){return this._currentStopFrames=0,this._firstRender&&(this._firstRender=!1,this.y>1||this.x>1)?(this.updateScrollPosition(),void this.trigger(e.EVENT_SCROLL_PROGRESS)):void(this._scrolling||(this._scrolling=!0,this._lastDirectionY=e.NONE,this._lastDirectionX=e.NONE,this.trigger(e.EVENT_SCROLL_START),m.animationFrame?this.nextFrameID=window.requestAnimationFrame(this.onNextFrame):this.onNextFrame()))}},{key:"onNextFrame",value:function(){var t=this;this._speedY=this._scrollY-this.scrollY,this._speedX=this._scrollX-this.scrollX;var i=+this.speedY+ +this.speedX;return this._scrolling&&0===i&&this._currentStopFrames++>this._stopFrames?void this.onScrollStop():(this.updateScrollPosition(),this._lastDirectionY!==this.directionY&&this.trigger("scroll:"+e.directionToString(this.directionY)),this._lastDirectionX!==this.directionX&&this.trigger("scroll:"+e.directionToString(this.directionX)),this._lastDirectionY=this.directionY,this._lastDirectionX=this.directionX,this.trigger(e.EVENT_SCROLL_PROGRESS),void(m.animationFrame?this.nextFrameID=window.requestAnimationFrame(this.onNextFrame):this._nextTimeout=setTimeout(function(){t.onNextFrame()},1e3/60)))}},{key:"onScrollStop",value:function(){this._scrolling=!1,this.updateScrollPosition(),this.trigger(e.EVENT_SCROLL_STOP),this._canScrollY&&(this.y<=0?this.trigger(e.EVENT_SCROLL_MIN):this.y+this.clientHeight>=this.scrollHeight&&this.trigger(e.EVENT_SCROLL_MAX)),this._canScrollX&&(this.x<=0?this.trigger(e.EVENT_SCROLL_MIN):this.x+this.clientWidth>=this.scrollWidth&&this.trigger(e.EVENT_SCROLL_MAX)),this._currentStopFrames=0,this._cancelNextFrame()}},{key:"_cancelNextFrame",value:function(){m.animationFrame?(window.cancelAnimationFrame(this.nextFrameID),this.nextFrameID=-1):clearTimeout(this._nextTimeout)}},{key:"destroyed",get:function(){return this._destroyed}},{key:"scrollPosition",get:function(){return this.getScrollPosition()}},{key:"directionY",get:function(){return!this._canScrollY||0===this.speedY&&!this._scrolling?this._directionY=e.NONE:this.speedY>0?this._directionY=e.UP:this.speedY<0&&(this._directionY=e.DOWN),this._directionY}},{key:"directionX",get:function(){return!this._canScrollX||0===this.speedX&&!this._scrolling?this._directionX=e.NONE:this.speedX>0?this._directionX=e.LEFT:this.speedX<0&&(this._directionX=e.RIGHT),this._directionX}},{key:"scrollTarget",get:function(){return this._scrollTarget}},{key:"delta",get:function(){return this.directionY}},{key:"scrolling",get:function(){return this._scrolling}},{key:"speedY",get:function(){return this._speedY}},{key:"speedX",get:function(){return this._speedX}},{key:"canScrollY",get:function(){return this._canScrollY}},{key:"canScrollX",get:function(){return this._canScrollX}},{key:"scrollY",get:function(){return this.scrollPosition.y}},{key:"y",get:function(){return this.scrollY}},{key:"scrollX",get:function(){return this.scrollPosition.x}},{key:"x",get:function(){return this.scrollX}},{key:"clientHeight",get:function(){return this._scrollTarget===window?window.innerHeight:this._scrollTarget.clientHeight}},{key:"clientWidth",get:function(){return this._scrollTarget===window?window.innerWidth:this._scrollTarget.clientWidth}},{key:"scrollHeight",get:function(){return this._scrollTarget===window?e.documentHeight:this._scrollTarget.scrollHeight}},{key:"scrollWidth",get:function(){return this._scrollTarget===window?e.documentWidth:this._scrollTarget.scrollWidth}}]),e}(d["default"]);_.UP=-1,_.DOWN=1,_.NONE=0,_.RIGHT=2,_.LEFT=-2,_.EVENT_SCROLL_PROGRESS="scroll:progress",_.EVENT_SCROLL_START="scroll:start",_.EVENT_SCROLL_STOP="scroll:stop",_.EVENT_SCROLL_DOWN="scroll:down",_.EVENT_SCROLL_UP="scroll:up",_.EVENT_SCROLL_MIN="scroll:min",_.EVENT_SCROLL_MAX="scroll:max",_.EVENT_SCROLL_RESIZE="scroll:resize",i["default"]=_;var p=null,m=function(){function t(){r(this,t)}return c(t,null,[{key:"animationFrame",get:function(){return null===p&&(p=!!(window.requestAnimationFrame||window.mozRequestAnimationFrame||window.webkitRequestAnimationFrame||window.msRequestAnimationFrame)),p}}]),t}();e.exports=i["default"]},{"./scroll-parent":3,delegatejs:1,eventdispatcher:2}]},{},[4])(4)});
!function(t){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=t();else if("function"==typeof define&&define.amd)define([],t);else{var e;e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this,e.ScrollFeatures=t()}}(function(){return function t(e,i,n){function r(s,l){if(!i[s]){if(!e[s]){var c="function"==typeof require&&require;if(!l&&c)return c(s,!0);if(o)return o(s,!0);var a=new Error("Cannot find module '"+s+"'");throw a.code="MODULE_NOT_FOUND",a}var u=i[s]={exports:{}};e[s][0].call(u.exports,function(t){var i=e[s][1][t];return r(i?i:t)},u,u.exports,t,e,i,n)}return i[s].exports}for(var o="function"==typeof require&&require,s=0;s<n.length;s++)r(n[s]);return r}({1:[function(t,e){var i=function(t,e){var i=arguments.length<=2?[]:[].slice.call(arguments,2);return function(){return e.apply(t,arguments.length?i.slice().concat([].slice.call(arguments)):i)}};e.exports=i},{}],2:[function(t,e,i){"use strict";function n(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function r(t){for(var e in t)if(t.hasOwnProperty(e))return!1;return!0}Object.defineProperty(i,"__esModule",{value:!0});var o=function(){function t(){var e=arguments.length<=0||void 0===arguments[0]?{}:arguments[0],i=e.target,r=e.currentTarget;n(this,t),this._eventMap={},this._destroyed=!1,this._target=i||this,this._currentTarget=r||this,this.on=this.bind=this.addEventListener=this.addListener,this.off=this.unbind=this.removeEventListener=this.removeListener,this.once=this.one=this.addListenerOnce,this.emit=this.trigger=this.dispatchEvent=this.dispatch}return t.prototype.addListener=function(t,e){var i=this.getListener(t);return i?-1===i.indexOf(e)&&i.push(e):this._eventMap[t]=[e],this},t.prototype.addListenerOnce=function(t,e){var i=this,n=function(r){e(r),i.off(t,n),e=null,n=null};return this.on(t,n)},t.prototype.removeListener=function(t,e){if(!e)return this.removeAllListener(t);var i=this.getListener(t);if(i){var n=i.indexOf(e);n>-1&&(i=i.splice(n,1),i.length||delete this._eventMap[t])}return this},t.prototype.removeAllListener=function(t){var e=this.getListener(t);return e&&(this._eventMap[t].length=0,delete this._eventMap[t]),this},t.prototype.hasListener=function(t){return null!==this.getListener(t)},t.prototype.hasListeners=function(){return null!==this._eventMap&&void 0!==this._eventMap&&!r(this._eventMap)},t.prototype.dispatch=function(t,e){var i=this.getListener(t);if(i){e=e||{},e.type=t,e.target=e.target||this._target,e.currentTarget=e.currentTarget||this._currentTarget;for(var n=-1;++n<i.length;)i[n](e)}return this},t.prototype.getListener=function(t){var e=this._eventMap?this._eventMap[t]:null;return e||null},t.prototype.destroy=function(){if(this._eventMap){for(var t in this._eventMap)this.removeAllListener(t);this._eventMap=null}return this._destroyed=!0,this},t}();i["default"]=o,e.exports=i["default"]},{}],3:[function(t,e){"use strict";var i=/(auto|scroll)/,n=function(t){var e=window.getComputedStyle(t,null);return i.test(e.getPropertyValue("overflow")+e.getPropertyValue("overflow-y")+e.getPropertyValue("overflow-x"))};e.exports=n},{}],4:[function(t,e){"use strict";var i=t("./has-overflow"),n=function(t){if(!(t instanceof HTMLElement))return window;for(;t.parentNode;){if(t.parentNode===document.body)return window;if(i(t.parentNode))return t.parentNode;t=t.parentNode}return window};e.exports=n},{"./has-overflow":3}],5:[function(t,e,i){"use strict";function n(t){return t&&t.__esModule?t:{"default":t}}function r(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function o(t,e){if(!t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!e||"object"!=typeof e&&"function"!=typeof e?t:e}function s(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function, not "+typeof e);t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,enumerable:!1,writable:!0,configurable:!0}}),e&&(Object.setPrototypeOf?Object.setPrototypeOf(t,e):t.__proto__=e)}Object.defineProperty(i,"__esModule",{value:!0});var l=function v(t,e,i){null===t&&(t=Function.prototype);var n=Object.getOwnPropertyDescriptor(t,e);if(void 0===n){var r=Object.getPrototypeOf(t);return null===r?void 0:v(r,e,i)}if("value"in n)return n.value;var o=n.get;return void 0===o?void 0:o.call(i)},c=function(){function t(t,e){for(var i=0;i<e.length;i++){var n=e[i];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,n.key,n)}}return function(e,i,n){return i&&t(e.prototype,i),n&&t(e,n),e}}(),a=t("delegatejs"),u=n(a),h=t("eventdispatcher"),d=n(h),f=t("./scroll-parent"),g=n(f),_=function(t){function e(){var t=arguments.length<=0||void 0===arguments[0]?window:arguments[0],i=arguments.length<=1||void 0===arguments[1]?{}:arguments[1];if(r(this,e),e.hasInstance(t)){var n;return n=e.getInstance(t),o(s,n)}var s=o(this,(e.__proto__||Object.getPrototypeOf(e)).call(this,{target:t}));return t.scrollFeatures=s,s._scrollTarget=t,s.options=i,m.animationFrame&&e.unprefixAnimationFrame(),s.init(),s}return s(e,t),c(e,null,[{key:"getInstance",value:function(t,i){return t.scrollFeatures?t.scrollFeatures:new e(t,i)}},{key:"hasInstance",value:function(t){return"undefined"!=typeof t.scrollFeatures}},{key:"getScrollParent",value:function(t){return g["default"](t)}},{key:"unprefixAnimationFrame",value:function(){window.requestAnimationFrame||(window.requestAnimationFrame=window.requestAnimationFrame||window.mozRequestAnimationFrame||window.webkitRequestAnimationFrame||window.msRequestAnimationFrame,window.cancelAnimationFrame=window.cancelAnimationFrame||window.mozCancelAnimationFrame||window.webkitCancelAnimationFrame||window.msCancelAnimationFrame)}},{key:"directionToString",value:function(t){switch(t){case e.UP:return"up";case e.DOWN:return"down";case e.NONE:return"none";case e.LEFT:return"left";case e.RIGHT:return"right"}}},{key:"windowScrollY",get:function(){return window.pageYOffset||window.scrollY||0}},{key:"windowScrollX",get:function(){return window.pageXOffset||window.scrollX||0}},{key:"documentHeight",get:function(){return Math.max(document.body.scrollHeight,document.body.offsetHeight,document.documentElement.clientHeight,document.documentElement.scrollHeight,document.documentElement.offsetHeight)}},{key:"documentWidth",get:function(){return Math.max(document.body.scrollWidth,document.body.offsetWidth,document.documentElement.clientWidth,document.documentElement.scrollWidth,document.documentElement.offsetWidth)}}]),c(e,[{key:"init",value:function(){var t=this;if(this._destroyed=!1,this._scrollY=0,this._scrollX=0,this._speedY=0,this._speedX=0,this._lastSpeed=0,this._lastDirectionY=e.NONE,this._lastDirectionX=e.NONE,this._stopFrames=3,this._currentStopFrames=0,this._firstRender=!0,this._directionY=e.NONE,this._directionX=e.NONE,this._scrolling=!1,this._canScrollY=!1,this._canScrollX=!1,this.getScrollPosition=u["default"](this,this._scrollTarget===window?this._getWindowScrollPosition:this._getElementScrollPosition),this.onResize=u["default"](this,function(){return t.trigger(e.EVENT_SCROLL_RESIZE)}),this.onScroll=u["default"](this,this.onScroll),this.onNextFrame=u["default"](this,this.onNextFrame),this.updateScrollPosition(),this._scrollTarget!==window){var i=/(auto|scroll)/,n=window.getComputedStyle(this._scrollTarget,null);this._canScrollY=i.test(n.getPropertyValue("overflow-y")),this._canScrollX=i.test(n.getPropertyValue("overflow-x"))}else this._canScrollY=this.clientHeight<this.scrollHeight,this._canScrollX=this.clientWidth<this.scrollWidth;this._scrollTarget.addEventListener?(this._scrollTarget.addEventListener("scroll",this.onScroll,!1),this._scrollTarget.addEventListener("resize",this.onResize,!1)):this._scrollTarget.attachEvent&&(this._scrollTarget.attachEvent("scroll",this.onScroll),this._scrollTarget.attachEvent("resize",this.onResize))}},{key:"destroy",value:function(){this._destroyed||(this._cancelNextFrame(),l(e.prototype.__proto__||Object.getPrototypeOf(e.prototype),"destroy",this).call(this),this._scrollTarget.addEventListener?(this._scrollTarget.removeEventListener("scroll",this.onScroll),this._scrollTarget.removeEventListener("resize",this.onResize)):this._scrollTarget.attachEvent&&(this._scrollTarget.detachEvent("scroll",this.onScroll),this._scrollTarget.detachEvent("resize",this.onResize)),this.onResize=null,this.onScroll=null,this.getScrollPosition=null,this.onNextFrame=null,delete this._scrollTarget.scrollFeatures,this._scrollTarget=null,this._destroyed=!0)}},{key:"updateScrollPosition",value:function(){this._scrollY=this.scrollY,this._scrollX=this.scrollX}},{key:"_getWindowScrollPosition",value:function(){return{y:e.windowScrollY,x:e.windowScrollX}}},{key:"_getElementScrollPosition",value:function(){return{y:this._scrollTarget.scrollTop,x:this._scrollTarget.scrollLeft}}},{key:"onScroll",value:function(){return this._currentStopFrames=0,this._firstRender&&(this._firstRender=!1,this.y>1||this.x>1)?(this.updateScrollPosition(),void this.trigger(e.EVENT_SCROLL_PROGRESS)):void(this._scrolling||(this._scrolling=!0,this._lastDirectionY=e.NONE,this._lastDirectionX=e.NONE,this.trigger(e.EVENT_SCROLL_START),m.animationFrame?this.nextFrameID=window.requestAnimationFrame(this.onNextFrame):this.onNextFrame()))}},{key:"onNextFrame",value:function(){var t=this;this._speedY=this._scrollY-this.scrollY,this._speedX=this._scrollX-this.scrollX;var i=+this.speedY+ +this.speedX;return this._scrolling&&0===i&&this._currentStopFrames++>this._stopFrames?void this.onScrollStop():(this.updateScrollPosition(),this._lastDirectionY!==this.directionY&&this.trigger("scroll:"+e.directionToString(this.directionY)),this._lastDirectionX!==this.directionX&&this.trigger("scroll:"+e.directionToString(this.directionX)),this._lastDirectionY=this.directionY,this._lastDirectionX=this.directionX,this.trigger(e.EVENT_SCROLL_PROGRESS),void(m.animationFrame?this.nextFrameID=window.requestAnimationFrame(this.onNextFrame):this._nextTimeout=setTimeout(function(){t.onNextFrame()},1e3/60)))}},{key:"onScrollStop",value:function(){this._scrolling=!1,this.updateScrollPosition(),this.trigger(e.EVENT_SCROLL_STOP),this._canScrollY&&(this.y<=0?this.trigger(e.EVENT_SCROLL_MIN):this.y+this.clientHeight>=this.scrollHeight&&this.trigger(e.EVENT_SCROLL_MAX)),this._canScrollX&&(this.x<=0?this.trigger(e.EVENT_SCROLL_MIN):this.x+this.clientWidth>=this.scrollWidth&&this.trigger(e.EVENT_SCROLL_MAX)),this._currentStopFrames=0,this._cancelNextFrame()}},{key:"_cancelNextFrame",value:function(){m.animationFrame?(window.cancelAnimationFrame(this.nextFrameID),this.nextFrameID=-1):clearTimeout(this._nextTimeout)}},{key:"destroyed",get:function(){return this._destroyed}},{key:"scrollPosition",get:function(){return this.getScrollPosition()}},{key:"directionY",get:function(){return!this._canScrollY||0===this.speedY&&!this._scrolling?this._directionY=e.NONE:this.speedY>0?this._directionY=e.UP:this.speedY<0&&(this._directionY=e.DOWN),this._directionY}},{key:"directionX",get:function(){return!this._canScrollX||0===this.speedX&&!this._scrolling?this._directionX=e.NONE:this.speedX>0?this._directionX=e.LEFT:this.speedX<0&&(this._directionX=e.RIGHT),this._directionX}},{key:"scrollTarget",get:function(){return this._scrollTarget}},{key:"delta",get:function(){return this.directionY}},{key:"scrolling",get:function(){return this._scrolling}},{key:"speedY",get:function(){return this._speedY}},{key:"speedX",get:function(){return this._speedX}},{key:"canScrollY",get:function(){return this._canScrollY}},{key:"canScrollX",get:function(){return this._canScrollX}},{key:"scrollY",get:function(){return this.scrollPosition.y}},{key:"y",get:function(){return this.scrollY}},{key:"scrollX",get:function(){return this.scrollPosition.x}},{key:"x",get:function(){return this.scrollX}},{key:"clientHeight",get:function(){return this._scrollTarget===window?window.innerHeight:this._scrollTarget.clientHeight}},{key:"clientWidth",get:function(){return this._scrollTarget===window?window.innerWidth:this._scrollTarget.clientWidth}},{key:"scrollHeight",get:function(){return this._scrollTarget===window?e.documentHeight:this._scrollTarget.scrollHeight}},{key:"scrollWidth",get:function(){return this._scrollTarget===window?e.documentWidth:this._scrollTarget.scrollWidth}}]),e}(d["default"]);_.UP=-1,_.DOWN=1,_.NONE=0,_.RIGHT=2,_.LEFT=-2,_.EVENT_SCROLL_PROGRESS="scroll:progress",_.EVENT_SCROLL_START="scroll:start",_.EVENT_SCROLL_STOP="scroll:stop",_.EVENT_SCROLL_DOWN="scroll:down",_.EVENT_SCROLL_UP="scroll:up",_.EVENT_SCROLL_MIN="scroll:min",_.EVENT_SCROLL_MAX="scroll:max",_.EVENT_SCROLL_RESIZE="scroll:resize",i["default"]=_;var p=null,m=function(){function t(){r(this,t)}return c(t,null,[{key:"animationFrame",get:function(){return null===p&&(p=!!(window.requestAnimationFrame||window.mozRequestAnimationFrame||window.webkitRequestAnimationFrame||window.msRequestAnimationFrame)),p}}]),t}();e.exports=i["default"]},{"./scroll-parent":4,delegatejs:1,eventdispatcher:2}]},{},[5])(5)});
{
"name": "scrollfeatures",
"version": "1.0.2",
"version": "1.1.0",
"description": "Performant Custom Scroll Features and Events",

@@ -5,0 +5,0 @@ "main": "dist/scrollfeatures.js",

@@ -1,4 +0,4 @@

var regex = /(auto|scroll)/;
const hasOverflow = require('./has-overflow');
var scrollParent = function(element) {
const scrollParent = element => {

@@ -13,10 +13,8 @@ if (!(element instanceof HTMLElement)) {

}
var style = window.getComputedStyle(element.parentNode, null);
if (regex.test(style.getPropertyValue('overflow') + style.getPropertyValue('overflow-y') + style.getPropertyValue('overflow-x'))) {
if(hasOverflow(element.parentNode)){
return element.parentNode;
}
element = element.parentNode;
}
return window;

@@ -23,0 +21,0 @@ };

@@ -18,3 +18,3 @@ import delegate from 'delegatejs';

static getScrollParent(element){
static getScrollParent(element) {
return scrollParent(element);

@@ -115,3 +115,3 @@ }

this.getScrollPosition = delegate(this, (this._scrollTarget === window ? this._getWindowScrollPosition : this._getElementScrollPosition ));
this.getScrollPosition = delegate(this, (this._scrollTarget === window ? this._getWindowScrollPosition : this._getElementScrollPosition));

@@ -124,9 +124,10 @@ this.onResize = delegate(this, () => this.trigger(ScrollFeatures.EVENT_SCROLL_RESIZE));

this._canScrollY = this.clientHeight < this.scrollHeight;
this._canScrollX = this.clientWidth < this.scrollWidth;
if (this._scrollTarget !== window) {
var style = window.getComputedStyle(this._scrollTarget);
this._canScrollY = style['overflow-y'] !== 'hidden';
this._canScrollX = style['overflow-x'] !== 'hidden';
const regex = /(auto|scroll)/;
const style = window.getComputedStyle(this._scrollTarget, null);
this._canScrollY = regex.test(style.getPropertyValue('overflow-y'));
this._canScrollX = regex.test(style.getPropertyValue('overflow-x'));
}else{
this._canScrollY = this.clientHeight < this.scrollHeight;
this._canScrollX = this.clientWidth < this.scrollWidth;
}

@@ -165,2 +166,3 @@

this.onNextFrame = null;
delete this._scrollTarget.scrollFeatures;
this._scrollTarget = null;

@@ -237,4 +239,2 @@ this._destroyed = true;

get scrollY() {

@@ -314,4 +314,2 @@ return this.scrollPosition.y;

onNextFrame() {
// this._lastSpeed = this.speedY;
this._speedY = this._scrollY - this.scrollY;

@@ -391,3 +389,3 @@ this._speedX = this._scrollX - this.scrollX;

static get animationFrame() {
if(_animationFrame === null){
if (_animationFrame === null) {
_animationFrame = !!(window.requestAnimationFrame || window.mozRequestAnimationFrame || window.webkitRequestAnimationFrame || window.msRequestAnimationFrame);

@@ -394,0 +392,0 @@ }

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