From 71838b9f7237c24548d31b79e00ac6542fc2544e Mon Sep 17 00:00:00 2001 From: Hyunje Alex Jun Date: Sat, 14 Dec 2013 16:25:36 +0900 Subject: [PATCH] Don't prevent the default scrolling for the inactive axis. --- src/perfect-scrollbar.js | 62 ++++++++++++++++------------------------ 1 file changed, 24 insertions(+), 38 deletions(-) diff --git a/src/perfect-scrollbar.js b/src/perfect-scrollbar.js index 93f089c..8ca623f 100644 --- a/src/perfect-scrollbar.js +++ b/src/perfect-scrollbar.js @@ -245,27 +245,32 @@ currentPageY = null; }; + // check if the default scrolling should be prevented. + var shouldPreventDefault = function (deltaX, deltaY) { + var scrollTop = $this.scrollTop(); + if (deltaX === 0) { + if (!scrollbarYActive) { + return false; + } + if ((scrollTop === 0 && deltaY > 0) || (scrollTop >= contentHeight - containerHeight && deltaY < 0)) { + return !settings.wheelPropagation; + } + } + + var scrollLeft = $this.scrollLeft(); + if (deltaY === 0) { + if (!scrollbarXActive) { + return false; + } + if ((scrollLeft === 0 && deltaX < 0) || (scrollLeft >= contentWidth - containerWidth && deltaX > 0)) { + return !settings.wheelPropagation; + } + } + return true; + }; + // bind handlers var bindMouseWheelHandler = function () { - var shouldPreventDefault = function (deltaX, deltaY) { - var scrollTop = $this.scrollTop(); - if (scrollTop === 0 && deltaY > 0 && deltaX === 0) { - return !settings.wheelPropagation; - } - else if (scrollTop >= contentHeight - containerHeight && deltaY < 0 && deltaX === 0) { - return !settings.wheelPropagation; - } - - var scrollLeft = $this.scrollLeft(); - if (scrollLeft === 0 && deltaX < 0 && deltaY === 0) { - return !settings.wheelPropagation; - } - else if (scrollLeft >= contentWidth - containerWidth && deltaX > 0 && deltaY === 0) { - return !settings.wheelPropagation; - } - return true; - }; - var shouldPrevent = false; $this.bind('mousewheel.perfect-scrollbar', function (e, delta, deltaX, deltaY) { if (!settings.useBothWheelAxes) { @@ -309,25 +314,6 @@ }; var bindKeyboardHandler = function () { - var shouldPreventDefault = function (deltaX, deltaY) { - var scrollTop = $this.scrollTop(); - if (scrollTop === 0 && deltaY > 0 && deltaX === 0) { - return false; - } - else if (scrollTop >= contentHeight - containerHeight && deltaY < 0 && deltaX === 0) { - return false; - } - - var scrollLeft = $this.scrollLeft(); - if (scrollLeft === 0 && deltaX < 0 && deltaY === 0) { - return false; - } - else if (scrollLeft >= contentWidth - containerWidth && deltaX > 0 && deltaY === 0) { - return false; - } - return true; - }; - var hovered = false; $this.bind('mouseenter.perfect-scrollbar', function (e) { hovered = true;