[英]How to achieve something like gravity to div so when I drag div close to glue them, distance =0?
I have two divs inside one bigger div like 我在一个较大的div中有两个div,例如
<div id='container'>
<div class='demo'></div>
<div class='demo'></div>
</div>
and 和
$('.demo')
.resizable()
.draggable()
.droppable();
And I can fetch coordinates and size of .demo divs after resize and drag. 调整大小和拖动后,我可以获取.demo div的坐标和大小。 My question is how to achieve something like gravity to that div so when I drag on .demo div close to another .demo div ( for example when distance between them are less than 5px) to glue them, distance =0 ? 我的问题是如何实现该div的重力作用,因此当我在.demo div上靠近另一个.demo div拖动时(例如,当它们之间的距离小于5px时)将它们粘在一起,而距离= 0? In production I am going to have lot off divs with class='.demo' so it is heavy to calculate that manually. 在生产中,我将在class ='。demo'的divs上花很多钱,所以手动计算该值很重。 Does anyone have solution for this ? 有人对此有解决方案吗? Did anyone work with jPhysics plugin ? 有没有人使用jPhysics插件?
Surely it's just a case of when a drop event is triggered looping through all the coordinates, and if the right of one box is within say 10px of the left of another, moving the second box into place, then repeating for the vertical measurements. 当然,这是触发下降事件循环遍历所有坐标的一种情况,并且如果一个框的右侧在另一个框的左侧的10像素之内,则将第二个框移到适当位置,然后重复进行垂直测量。
I can't imagine that is too complex. 我无法想象这太复杂了。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.