How to detect horizontal scrolling in jQuery?

Solution 1:

This seems to work.

var lastScrollLeft = 0;
$(window).scroll(function() {
    var documentScrollLeft = $(document).scrollLeft();
    if (lastScrollLeft != documentScrollLeft) {
        console.log('scroll x');
        lastScrollLeft = documentScrollLeft;
    }
});

jsFiddle.

Solution 2:

An update that shows direction left or right in a horizontal scroll based on code above:

var lastPos = 0;
$(window).scroll(function() {
    var currPos = $(document).scrollLeft();

    if (lastPos < currPos) {
        console.log('scroll right');
    } 
    if (lastPos > currPos) 
    {
        console.log('scroll left');
    }

    lastPos = currPos;
});

Test it at http://jsfiddle.net/EsPk7/7/