对不起,伙计们..没有时间进一步解释,因为我们已经接近死胡同了。这是我正在使用的:
有三个 div 应用了 '.groupWrapper' 类,#listaUno #listaDos #listaInicial。有两种 div 模块,都是向左浮动的,宽度基本不同,167x159 和 342x159,容器 #listaUno 设置宽度为 346px(可以容纳两个小模块或一个大模块),而 #listaDos 有 690px(最多四个小模块)。
使用 jQuery-UI 中的 Sortables ..
$(document).ready(function(){
//change png to gif for IE as its very jumpy
if ($.browser.msie) {
$("img.iconico").attr("src", function() {
valor = this.src.replace(".png",".gif");
return valor;
});
}
//all three groupWrapper div elements are now draggable
$(".groupWrapper").sortable({
connectWith: '.groupWrapper',
items: 'div',
scroll: true,
opacity: 0.6,
receive: function(event, ui) { hemosCambiado(); }
});
$(".groupWrapper").disableSelection();
});
function init() {
$(".groupWrapper").sortable({
connectWith: '.groupWrapper',
items: 'div',
scroll: true,
opacity: 0.6,
receive: function(event, ui) { hemosCambiado(); }
});
$(".groupWrapper").disableSelection();
};
function hemosCambiado() {
var obj;
elemListaUno = $('#listaUno div').size(); //num elements in listaUno
elemListaDos = $('#listaDos div').size(); //num elements in listaDos
elemListaInicial = $('#listaInicial div').size(); //num elements in listaInicial
anchoLista1 = $('#izquierda').width(); //should be 346px;
anchoLista2 = $('#caja-modulos2').width(); //should be 690px;
//listaUno should have 2 or less elements, less than given width
anchoElems1 = 0;
$('#listaUno div').each( function(i,elem) {
anchoElems1 += $(elem).width();
});
if((elemListaUno>2) || (anchoElems1>anchoLista1)){
//surplus elements are sent back to listaInicial
$('#listaInicial').append($('#listaUno div:last-child'));
}
//listaUno should have 4 or less elements, less than given width
anchoElems2 = 0;
$('#listaDos div').each( function(i,elem) {
anchoElems2 += $(elem).width();
});
if((elemListaDos>4) || (anchoElems2>anchoLista2)){
//surplus elements are sent back to listaInicial
$('#listaInicial').append($('#listaDos div:last-child'));
}
$(".groupWrapper").sortable( 'refresh' );
init(); //for some reason, elements appended aren't included as dragable again in IE versions, so the need to be initialized again.
}
这在 FireFox、IE7、Safari 等上运行良好……但在 IE6 上,被拖动的元素,在其他页面元素下做一些跳跃的东西,或者链接到鼠标但距离它 500 像素,以及不同的其他混乱的东西..