diff --git a/index.js b/index.js index b3c8e30..2ae81c8 100644 --- a/index.js +++ b/index.js @@ -32,11 +32,13 @@ export default class Smooth { ticking: false } this.vs = this.vars.native ? null : new vs({ - limitInertia: this.options.vs && this.options.vs.limitInertia || false, + limitInertia: this.options.vs && this.options.vs.hasOwnProperty('limitInertia') ? this.options.vs.limitInertia : false, mouseMultiplier: this.options.vs && this.options.vs.mouseMultiplier || 1, touchMultiplier: this.options.vs && this.options.vs.touchMultiplier || 1.5, firefoxMultiplier: this.options.vs && this.options.vs.firefoxMultiplier || 30, - preventTouch: this.options.vs && this.options.vs.preventTouch || true + useKeyboard: this.options.vs && this.options.vs.hasOwnProperty('useKeyboard') ? this.options.vs.useKeyboard : true, + preventTouch: this.options.vs && this.options.vs.hasOwnProperty('preventTouch') ? this.options.vs.preventTouch : true, + passive: this.options.vs && this.options.vs.hasOwnProperty('passive') ? this.options.vs.passive : undefined, }) this.dom = { listener: this.options.listener || document.body, diff --git a/package-lock.json b/package-lock.json index 8c29e5b..04f5b2a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "smooth-scrolling", - "version": "2.3.11", + "version": "2.3.12", "lockfileVersion": 1, "requires": true, "dependencies": { @@ -2893,9 +2893,9 @@ } }, "lethargy": { - "version": "1.0.4", - "resolved": "https://registry.npmjs.org/lethargy/-/lethargy-1.0.4.tgz", - "integrity": "sha1-RZ38WqSaEO+QVjALkOwDqI47mK8=" + "version": "1.0.7", + "resolved": "https://registry.npmjs.org/lethargy/-/lethargy-1.0.7.tgz", + "integrity": "sha512-+IhiyZpw27A0KrtlfsrC1DcCgUYHqtWTqoa4CuJPyX7dmwF0b9bInWVkLrvn7yE88sEq86NxOSVtPhaVmE7C6A==" }, "lodash": { "version": "4.17.11", @@ -4168,9 +4168,9 @@ "dev": true }, "virtual-scroll": { - "version": "1.3.1", - "resolved": "https://registry.npmjs.org/virtual-scroll/-/virtual-scroll-1.3.1.tgz", - "integrity": "sha1-emwK+ZEEG9+hTqCnkZARV1vmBgE=", + "version": "1.5.1", + "resolved": "https://registry.npmjs.org/virtual-scroll/-/virtual-scroll-1.5.1.tgz", + "integrity": "sha512-QD6wnfbziuRjpRuEFFXCacR/uCzikc5mflGDggN9iVyzJm5//32YnvQ+Bh48RR6io5GW6HqQhAHMR4ILLTY1uQ==", "requires": { "bindall-standalone": "^1.0.5", "lethargy": "^1.0.2", diff --git a/package.json b/package.json index 1d3a922..7b2bb1a 100644 --- a/package.json +++ b/package.json @@ -8,7 +8,7 @@ "dom-create-element": "^1.0.2", "dom-events": "^0.1.1", "prefix": "^1.0.0", - "virtual-scroll": "^1.2.1" + "virtual-scroll": "^1.5.1" }, "devDependencies": { "@babel/core": "^7.4.4", diff --git a/smooth-scrolling.js b/smooth-scrolling.js index 1522109..d172ca8 100644 --- a/smooth-scrolling.js +++ b/smooth-scrolling.js @@ -57,11 +57,13 @@ function () { ticking: false }; this.vs = this.vars["native"] ? null : new _virtualScroll["default"]({ - limitInertia: this.options.vs && this.options.vs.limitInertia || false, + limitInertia: this.options.vs && this.options.vs.hasOwnProperty('limitInertia') ? this.options.vs.limitInertia : false, mouseMultiplier: this.options.vs && this.options.vs.mouseMultiplier || 1, touchMultiplier: this.options.vs && this.options.vs.touchMultiplier || 1.5, firefoxMultiplier: this.options.vs && this.options.vs.firefoxMultiplier || 30, - preventTouch: this.options.vs && this.options.vs.preventTouch || true + useKeyboard: this.options.vs && this.options.vs.hasOwnProperty('useKeyboard') ? this.options.vs.useKeyboard : true, + preventTouch: this.options.vs && this.options.vs.hasOwnProperty('preventTouch') ? this.options.vs.preventTouch : true, + passive: this.options.vs && this.options.vs.hasOwnProperty('passive') ? this.options.vs.passive : undefined }); this.dom = { listener: this.options.listener || document.body, @@ -1246,7 +1248,9 @@ function VirtualScroll(options) { keyStep: 120, preventTouch: false, unpreventTouchClass: 'vs-touchmove-allowed', - limitInertia: false + limitInertia: false, + useKeyboard: true, + useTouch: true }, options); if (this.options.limitInertia) this._lethargy = new Lethargy(); @@ -1373,7 +1377,7 @@ VirtualScroll.prototype._bind = function() { if(support.hasWheelEvent) this.el.addEventListener('wheel', this._onWheel, this.listenerOptions); if(support.hasMouseWheelEvent) this.el.addEventListener('mousewheel', this._onMouseWheel, this.listenerOptions); - if(support.hasTouch) { + if(support.hasTouch && this.options.useTouch) { this.el.addEventListener('touchstart', this._onTouchStart, this.listenerOptions); this.el.addEventListener('touchmove', this._onTouchMove, this.listenerOptions); } @@ -1385,7 +1389,7 @@ VirtualScroll.prototype._bind = function() { this.el.addEventListener('MSPointerMove', this._onTouchMove, true); } - if(support.hasKeyDown) document.addEventListener('keydown', this._onKeyDown); + if(support.hasKeyDown && this.options.useKeyboard) document.addEventListener('keydown', this._onKeyDown); }; VirtualScroll.prototype._unbind = function() { @@ -1403,7 +1407,7 @@ VirtualScroll.prototype._unbind = function() { this.el.removeEventListener('MSPointerMove', this._onTouchMove, true); } - if(support.hasKeyDown) document.removeEventListener('keydown', this._onKeyDown); + if(support.hasKeyDown && this.options.useKeyboard) document.removeEventListener('keydown', this._onKeyDown); }; VirtualScroll.prototype.on = function(cb, ctx) {