简体   繁体   English

如何实现类似于重力的div,以便当我将div拖近以粘合它们时,距离= 0?

[英]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.

相关问题 我想在div中移动图像,以便包含div的图像准确显示其大小 - I would like to move images in a div so the containing div displays them exactly their size 当div失去焦点时如何关闭div? - How to close div when div loses focus? 拖放时如何替换div的内容 - How can I replace the content of a div when I drag and drop 想打开另一个div时关闭一个div - Would like to close a div when open another div 使DIV关闭图标与DIV一起拖动 - Making the DIV close icon drag along with the DIV javascript中的动画功能,当我单击它时需要对某物进行动画处理,以便一个div进入1种方式,另一个div进入另一种方式 - Animate function in javascript, I need to animate something when I click on it so that one div goes 1 way and the other div goes the other way 拖动DIV时如何将id的值传递给函数? - How to pass value of a id to a function when I drag a DIV? 当我单击子 div 时如何关闭父 div 函数,当我再次单击父 div 时,该函数将活动 - How can I close parent div function when I clicked child div and when I clicked parent div again, the function will activity 如何捕获此事件,当我左键单击然后在div上移动一些位置(而不是拖动div) - how to catch this event that when i left click and then move some where (not drag some div ) on a div 如何在div内拖动div? - How to drag a div within a div?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM