From 32814039c471a357f2fd0220f9f02c5a18b40975 Mon Sep 17 00:00:00 2001 From: Kyle Mellander Date: Wed, 7 Jun 2017 12:36:02 -0700 Subject: [PATCH] Add support for preventing opening menu when vertically scrolling --- index.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index 0449e40..6616334 100644 --- a/index.js +++ b/index.js @@ -63,6 +63,7 @@ function Slideout(options) { // Sets default values this._startOffsetX = 0; + this._startOffsetY = 0; this._currentOffsetX = 0; this._opening = false; this._moved = false; @@ -81,6 +82,7 @@ function Slideout(options) { this._tolerance = parseInt(options.tolerance, 10) || 70; this._padding = this._translateTo = parseInt(options.padding, 10) || 256; this._orientation = this._side === 'right' ? -1 : 1; + this._verticalRatio = options.verticalRatio || 2; this._translateTo *= this._orientation; // Sets classnames @@ -219,6 +221,7 @@ Slideout.prototype._initTouchEvents = function() { self._moved = false; self._opening = false; self._startOffsetX = eve.touches[0].pageX; + self._startOffsetY = eve.touches[0].pageY; self._preventOpen = (!self._touch || (!self.isOpen() && self.menu.clientWidth !== 0)); }; @@ -261,13 +264,14 @@ Slideout.prototype._initTouchEvents = function() { } var dif_x = eve.touches[0].clientX - self._startOffsetX; + var dif_y = eve.touches[0].clientY - self._startOffsetY; var translateX = self._currentOffsetX = dif_x; if (Math.abs(translateX) > self._padding) { return; } - if (Math.abs(dif_x) > 20) { + if (Math.abs(dif_x) > 20 && Math.abs(dif_y) * this._verticalRatio <= Math.abs(dif_x)) { self._opening = true;