( ) , change sortable. , "" LI , , , , LI float: left. .
, clear: both LI ( ), , LI. (, ), .
change, , DOM . jquery, , LI , clear: both.
function setClearsOnFirstColumn() {
var colNum = 0;
$(".myList").find( "li:not(.ui-sortable-helper)" ).each( function() {
var thisLiEl = $(this);
if( colNum == 0 )
thisLiEl.css( "clear", "both" );
else
thisLiEl.css( "clear", "none" );
colNum ++;
if( colNum == 2 ) colNum = 0;
} );
}
$(".myList").sortable( { change: setClearsOnFirstColumn, stop: setClearsOnFirstColumn } );
The notselector part is used to ignore the dragged LI element (identified by its class .ui-sortable-helper) when determining which LI elements are in the first column. (You can also shorten this with the help of even and odd jquery selectors - this is not done here because the fragment was adapted from a more general case to support more than two columns in the list.)
Please note that you also need to call setClearsOnFirstColumnafter the initial display of the list.)
source
share