Last active
June 15, 2016 16:33
-
-
Save JoshuaToenyes/80e0bf5747977e3b0c976700592f2c13 to your computer and use it in GitHub Desktop.
Prevent "back" and "forward" swipe navigation in Chrome for horizontal scrolling in some element.
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
(function ($) { | |
$(document).on('mousewheel', function(e) { | |
var $target = $(e.target).closest('.scrollable-h'); | |
var scroll = $target.scrollLeft(); | |
var maxScroll = $target.find('.scrollable-h-content').width() - $target.width(); | |
if(scroll <= 0) { | |
// Prevent "back" navigation. | |
if(scroll <= 0 && e.originalEvent.wheelDeltaX > 0) { | |
e.preventDefault(); | |
} | |
} | |
if(scroll >= maxScroll) { | |
// Prevent "forward" navigation. | |
if (scroll > 1 && e.originalEvent.wheelDeltaX < 0) { | |
e.preventDefault(); | |
} | |
} | |
});}(jQuery)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment