I hope this solution is useful to you ... it will work on all elements with the class name 'scroll-track'. You must also provide a new attribute to the scrollable element: data-scroll = '{"x": "0", "y": "0"}' You can check it here: http://jsfiddle.net/CgZDD/
-js -
$(document).ready(function(){ // make sure overflow is set to 'scroll' $('.scroll-track').css({ overflow: 'scroll' }); $('.scroll-track').scroll(function() { var scrollData = $(this).data('scroll'); if(scrollData.y > $(this).scrollTop()){ $('#scrollDir').append($(this).attr('id') + ' up'); }else if(scrollData.y != $(this).scrollTop()){ $('#scrollDir').append($(this).attr('id') + ' down'); } if(scrollData.x > $(this).scrollLeft()){ $('#scrollDir').append($(this).attr('id') + ' left'); }else if(scrollData.x != $(this).scrollLeft()){ $('#scrollDir').append($(this).attr('id') + ' right'); } $('#scrollDir').append('<br />'); scrollData.x = $(this).scrollLeft(); scrollData.y = $(this).scrollTop(); $(this).data('scroll', scrollData); }); });
Nick g
source share