Skip to content

Instantly share code, notes, and snippets.

@JoshuaToenyes
Last active June 15, 2016 16:33
Show Gist options
  • Save JoshuaToenyes/80e0bf5747977e3b0c976700592f2c13 to your computer and use it in GitHub Desktop.
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.
(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