From 741303f1bc9fe4a445abb22f69c8e66ccc881ff3 Mon Sep 17 00:00:00 2001 From: ssafejava Date: Thu, 6 Jun 2013 12:09:23 +0800 Subject: [PATCH] Support vertical lists of variable height by defining a dead zone when hovering over larger items. --- jquery.sortable.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/jquery.sortable.js b/jquery.sortable.js index 350d172..93be272 100644 --- a/jquery.sortable.js +++ b/jquery.sortable.js @@ -68,8 +68,16 @@ $.fn.sortable = function(options) { e.preventDefault(); e.originalEvent.dataTransfer.dropEffect = 'move'; if (items.is(this)) { + var draggingHeight = dragging.outerHeight(), thisHeight = $(this).outerHeight(); if (options.forcePlaceholderSize) { - placeholder.height(dragging.outerHeight()); + placeholder.height(draggingHeight); + } + // Check if $(this) is bigger than the draggable. If it is, we have to define a dead zone to prevent flickering + if (thisHeight > draggingHeight){ + // Dead zone? + var deadZone = thisHeight - draggingHeight, offsetTop = $(this).offset().top; + if(placeholder.index() < $(this).index() && e.originalEvent.pageY < offsetTop + deadZone) return false; + else if(placeholder.index() > $(this).index() && e.originalEvent.pageY > offsetTop + thisHeight - deadZone) return false; } dragging.hide(); $(this)[placeholder.index() < $(this).index() ? 'after' : 'before'](placeholder);