From b0a38741df0d1ddab96f144fa58b622be5a5263c Mon Sep 17 00:00:00 2001 From: Thomas Khyn Date: Thu, 14 Apr 2016 12:09:24 +1200 Subject: [PATCH 1/2] Mitigates rounding errors due to non-subpixel scroll values --- src/js/plugin/update-scroll.js | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/src/js/plugin/update-scroll.js b/src/js/plugin/update-scroll.js index 40863c7..85f0e3f 100644 --- a/src/js/plugin/update-scroll.js +++ b/src/js/plugin/update-scroll.js @@ -52,12 +52,26 @@ module.exports = function (element, axis, value) { var i = instances.get(element); if (axis === 'top' && value >= i.contentHeight - i.containerHeight) { - element.scrollTop = value = i.contentHeight - i.containerHeight; // don't allow scroll past container + // don't allow scroll past container + value = i.contentHeight - i.containerHeight; + if (Math.abs(value - element.scrollTop) <= 1) { + // mitigates rounding errors on non-subpixel scroll values + value = element.scrollTop; + } else { + element.scrollTop = value; + } element.dispatchEvent(yEndEvent); } if (axis === 'left' && value >= i.contentWidth - i.containerWidth) { - element.scrollLeft = value = i.contentWidth - i.containerWidth; // don't allow scroll past container + // don't allow scroll past container + value = i.contentWidth - i.containerWidth; + if (Math.abs(value - element.scrollLeft) <= 1) { + // mitigates rounding errors on non-subpixel scroll values + value = element.scrollLeft; + } else { + element.scrollLeft = value; + } element.dispatchEvent(xEndEvent); } From 2cac43ef39a0a5d029ee11eef045a1be525eb18d Mon Sep 17 00:00:00 2001 From: Thomas Khyn Date: Thu, 14 Apr 2016 12:25:50 +1200 Subject: [PATCH 2/2] Taking the absolute value is actually not necessary --- src/js/plugin/update-scroll.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/js/plugin/update-scroll.js b/src/js/plugin/update-scroll.js index 85f0e3f..1fb40e4 100644 --- a/src/js/plugin/update-scroll.js +++ b/src/js/plugin/update-scroll.js @@ -54,7 +54,7 @@ module.exports = function (element, axis, value) { if (axis === 'top' && value >= i.contentHeight - i.containerHeight) { // don't allow scroll past container value = i.contentHeight - i.containerHeight; - if (Math.abs(value - element.scrollTop) <= 1) { + if (value - element.scrollTop <= 1) { // mitigates rounding errors on non-subpixel scroll values value = element.scrollTop; } else { @@ -66,7 +66,7 @@ module.exports = function (element, axis, value) { if (axis === 'left' && value >= i.contentWidth - i.containerWidth) { // don't allow scroll past container value = i.contentWidth - i.containerWidth; - if (Math.abs(value - element.scrollLeft) <= 1) { + if (value - element.scrollLeft <= 1) { // mitigates rounding errors on non-subpixel scroll values value = element.scrollLeft; } else {