Espérons que cette solution est utile pour vous ... il fonctionne sur tous les éléments avec un nom de classe « scroll- Piste'. Vous devez également fournir un nouvel attribut à l'élément scrollable: données défilement = '{ "x": "0", "y": "0"}' Vous pouvez tester ici: 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);
});
});