Last active
October 17, 2016 16:52
-
-
Save 75th/2f85d8e916e3601c920bc1038c049457 to your computer and use it in GitHub Desktop.
Convert all scrolling to horizontal scrolling
This file contains hidden or 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
// Make vertical mousewheel movement scroll a page horizontally. | |
// | |
// Seems to work well with Mac trackpads and Magic Mouse on macOS. | |
// Also works with either scroll direction on macOS. | |
// If body has class 'scroll-horizontal' | |
if(document.body.className.split(' ').indexOf('scroll-horizontal') !== -1) { | |
['wheel', 'mousewheel', 'DOMMouseScroll'].forEach(function(eventName) { | |
// Test for browser support of event | |
if(typeof window['on' + eventName] !== 'undefined') { | |
window.addEventListener(eventName, function(e) { | |
// If scroll has both horizontal and vertical components, use the greater absolute value | |
var scrollAmount = Math.abs(e.deltaY) > Math.abs(e.deltaX) ? e.deltaY : e.deltaX; | |
window.scrollBy(scrollAmount, 0); | |
e.preventDefault(); | |
}); | |
} | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment