Skip to content

Commit

Permalink
fix navigation with horizontal sroll bar
Browse files Browse the repository at this point in the history
This fixes issue #2. Now we check that we have scrolled to either end of
the page before proceeding with the navigation.
  • Loading branch information
totu committed May 26, 2019
1 parent 1c1f926 commit 60c942f
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions swipe2nav.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,20 @@ const figureoutDirection = function(event)
const deltaY = event.deltaY;
let direction = NaN;

// Check we are horizontal scrolling and not vertically
if (Math.abs(deltaX) > 0 && Math.abs(deltaY) == 0)
// Check we are at either horizontal edge of the page
if (window.scrollX <= 0 || Math.ceil(window.scrollX) >= window.scrollMaxX)
{
// Go forwards
if (deltaX > 0)
direction = 1;
// Check we are horizontal scrolling and not vertically
if (Math.abs(deltaX) > 0 && Math.abs(deltaY) == 0)
{
// Go forwards
if (deltaX > 0)
direction = 1;

// Go forwards
else if (deltaX < 0)
direction = -1;
// Go forwards
else if (deltaX < 0)
direction = -1;
}
}

return direction;
Expand Down

0 comments on commit 60c942f

Please sign in to comment.