Created
May 22, 2013 22:46
-
-
Save mattsacks/5631556 to your computer and use it in GitHub Desktop.
Prevent back/forward gestures when scrolling an element left/right on OS X
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// prevent back/forward gestures when scrolling an element left/right on OS X | |
var preventHistorySwipe = function(element) { | |
// not even on the right platform bro | |
if (navigator.userAgent.indexOf('Macintosh') === -1) return; | |
element.addEventListener('mousewheel', function(e) { | |
var x = e.wheelDeltaX; | |
// scrolling up or down? then i don't give a shit | |
if (x === 0) return; | |
// get the current scroll | |
var scroll = element.scrollLeft; | |
var maxScroll = element.scrollWidth - element.clientWidth; | |
// scrolled to the left and scrolling left | |
if (scroll === 0 && x > 0) | |
e.preventDefault(); | |
// scrolled to the right and scrolling right | |
else if (scroll === maxScroll && x < 0) | |
e.preventDefault(); | |
}); | |
return element; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment