I came up with this solution:
var direction = {}; var bound = {}; var scrolling = false; var container = document.getElementById("container"); $('#table-container') .on('dragstart', draggable, function(event, ui) { bound = { right : $(container).offset().left + $(container).width() - 50, left : $(container).offset().left + 50, top : $(container).offset().top + 50, bottom : $(container).offset().top + $(container).height() - 50 }; }) .on('dragstop', draggable, function(event, ui) { direction = {}; }) .on('drag', draggable, function(event, ui) { direction.right = event.clientX - bound.right; direction.left = bound.left - event.clientX; direction.up = bound.top - event.clientY; direction.down = event.clientY - bound.bottom; if ((direction.right > 0 || direction.left > 0|| direction.up > 0 || direction.down > 0) && !scrolling) { scroll(); scrolling = true; } else { scrolling = false; } }); function scroll() { if (direction.right > 0) { container.scrollLeft = container.scrollLeft + (direction.right >> 1);
source share