本文介绍了jQuery Masonry,在div#container的中心添加一个新的div的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的HTML中有一些DIV,我想单击一些div,然后在div#container的中心添加一个新的div.并且页面可能reload,将第一个div放在这个新的div周围.

I have some DIV's in my HTML and I want click some div's then add a new div in the center of the div#container. and the page could reload, put the first pieces div's around this new div.

但是,这就是我需要的

however, this is what i need

这是我的代码, http://jsfiddle.net/PQGGT/
仍然有一个window resize函数.

Here is my code, http://jsfiddle.net/PQGGT/
there is still have a window resize function.

推荐答案

我在解决方案中的行动是通过将新元素附加到容器中的正确位置(通过计算其应放置的位置)来居中,然后遍历框元素的总宽度,并在中心位置的元素之前加上适当的边距,以使其完美居中.

My course of action in the solution was to center the new element by appending it to the right position in the container by calculating where it should be located, iterate through the box elements while totaling their widths and prepending the centered element in the right position with the appropriate margins to have it perfectly centered.

您可以在这里看到我的解决方案: http://jsfiddle.net/PQGGT/4/

You can see my solution here: http://jsfiddle.net/PQGGT/4/

我必须在代码中修复一些小问题,才能使其首先运行.

I had to fix a few small things in your code to make it run in the first place.

这篇关于jQuery Masonry,在div#container的中心添加一个新的div的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-28 15:48