我有一个页面,其中包含由用户选择确定的不同数量的列。
在更改时,为了争论,从三列更改为两列,我想从所有三列中获取所有内容(子 div),然后在现在剩余的两列之间重新平均分配(ish)。
这就是我到目前为止所拥有的。
// gather contents from source colums and store, store target divs as well
var source = jQuery(".col").contents();
var target = jQuery("#cols").contents();
// clear target divs (individually) now that their content is stored so we can append and re distribute source content
jQuery(".col").html('');
// insert source into target
jQuery(target).append(source);
#cols 是一个包含所有可见列的容器,而 .col 是这些单独的列中的每一个。因此,我成功地保存了每个单独列 (.col) 中的内容并将其附加到列容器 (#col) 中,然后将内容放入该容器的每个子项(每个列或 .col)中。
所以它工作正常,但它当然是复制每一列中的全部内容,我实际上想在每一列之间均匀地划分它。
我希望这是有道理的......有什么想法吗?
请参阅此处的示例http://jsfiddle.net/Cgdyq/单击屏幕选项以更改列设置,您会注意到内容随着所选列的列数而成倍增加。