UPDATE
since the sort event only fires when the user moves the mouse, you should use a function that checks the helper position every n milliseconds, for example:
edited by jsFiddle
var timerId = 0; function testPos (l , h){ timerId = window.setInterval(function(){ var leftUl = l var ulTop = leftUl.offset().top; var ulBottom = ulTop + leftUl.height(); console.log(h.offset().top >= ulTop && h.offset().top <= ulTop + 20) if(h.offset().top >= ulTop && h.offset().top <= ulTop + 20 ){ leftUl.scrollTop(leftUl.scrollTop() - 1) } if(h.offset().top +h.height() <= ulBottom && h.offset().top +h.height() >= ulBottom - 20 ){ leftUl.scrollTop(leftUl.scrollTop() + 1) } }, 10); }
and start the timer at start and clearInterval at stop
start : function (event , ui){ testPos ($('ul.static.sortable.connected-sortable') , ui.helper); }, stop: function( event, ui ) { clearInterval(timerId) ui.item.prev().children(".hint").hide(); var nextItemclass = ui.item.next().attr("class"); var prevItemClass = ui.item.prev().attr("class"); if ((nextItemclass == "sortableRow")&&(ui.item.parent().hasClass('static'))){ $(".right").append(ui.item.next()); } if ((prevItemClass == "sortableRow")&&(ui.item.parent().hasClass('static'))){ $(".right").append(ui.item.prev()); } if(prevItemClass == "not-sortable"){ ui.item.prev().addClass("highlight"); } },
You can do this with a sort event.
sort : function( event, ui ){ var leftUl = $('ul.static.sortable.connected-sortable') var ulTop = leftUl.offset().top; var ulBottom = ulTop + leftUl.height(); if(ui.offset.top >= ulTop && ui.offset.top <= ulTop + 20 ){ leftUl.scrollTop(leftUl.scrollTop() - 1) } if(ui.offset.top +ui.helper.height() <= ulBottom && ui.offset.top +ui.helper.height() >= ulBottom - 20 ){ leftUl.scrollTop(leftUl.scrollTop() + 1) } }
jsFiddle
source share