Jquery 划分然后附加到多个 div

发布于 2024-12-22 01:54:42 字数 849 浏览 4 评论 0原文

我有一个页面,其中包含由用户选择确定的不同列数。

为了争论起见,从三列更改为两列后,我想从所有三列中获取所有内容(子 div),然后将它们均匀地重新分布在现在剩余的两列之间。

这是我到目前为止所拥有的。

// 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/ 单击屏幕选项来更改列设置,您会注意到内容乘以所选列的列数。

I have a page with differentiating amounts of colums determined by user selection.

Upon changing, for arguments sake, from three to two colums I want to take all content (child divs) from all three colums and then re distribute them evenly(ish) between the now remaining two colums.

This is what I have so far.

// 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 is a container containing all visible colums and .col is each of these individual colums. So I am successfully saving the content from each individual colum (.col) and appending it to the colum container (#col) where it is then placing the content into each child of this container (each colum or .col).

So it is working fine but it is of course DUPLICATING the entire lot of content in each colum where I actually want to DIVIDE it between each colum evenly.

I hope this makes sense... any ideas?

See example here http://jsfiddle.net/Cgdyq/ click screen options to change colum settings and you will notice the content multiplying depending on colum number of colums selected.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

臻嫒无言 2024-12-29 01:54:43

通过将源除以列数并拆分数组,然后将每个结果块放入每个列中,并将复习列(如果存在)放入最后一个列中,可以解决问题。

Problem solved by dividing the source by the number of colums and splitting the array before placing each resulting chunk in each colum and the reaminder colum (if it exists) into the last colum.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文