From abfa2d99c24466c8869a3f1416d0257970ca8311 Mon Sep 17 00:00:00 2001 From: Frankie Robertson Date: Sun, 31 Jan 2016 17:32:25 +0200 Subject: [PATCH] Pick the nearest element in the direction of scrolling --- src/scrollsnap-polyfill.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/scrollsnap-polyfill.js b/src/scrollsnap-polyfill.js index 9c3714e..eb8a89e 100644 --- a/src/scrollsnap-polyfill.js +++ b/src/scrollsnap-polyfill.js @@ -320,8 +320,8 @@ // check if object snappoint is "close" enough to scrollable snappoint // not scrolled past element snap coords - if ((left <= snapCoords.x && left + getWidth(scrollObj) >= snapCoords.x && - top <= snapCoords.y && top + getHeight(scrollObj) >= snapCoords.y)) { + if ((left*primaryDirection <= snapCoords.x*primaryDirection && + top*primaryDirection <= snapCoords.y*primaryDirection)) { // ok, we found a snap point. currentIteration = i; // stay in bounds (minimum: 0, maxmimum: absolute height)